【发布时间】:2017-09-01 17:05:48
【问题描述】:
我最近在 JHipster 中发现并开始开发。
我面临的首要障碍之一是自动关闭警报。到目前为止,我了解到 JHipster 使用Bootstrap UI alerts,所以我正在尝试调整捆绑在sample project of JHipster 中的警报,当用户尝试登录时,它们会显示在主页中(绿色的那个):
警报的HTML代码如下:
<div ng-switch="vm.isAuthenticated()">
<div class="alert alert-success" ng-switch-when="true" data-translate="home.logged.message" translate-values="{username: '{{vm.account.login}}'}">
You are logged in as user "{{vm.account.login}}".
</div>
</div>
我修改如下:
<div class="alert alert-success" ng-switch-when="true" data-translate="home.logged.message" translate-values="{username: '{{vm.account.login}}'}" close="closeAlert()" ng-if="show" dismiss-on-timeout="3000" >
You are logged in as user "{{vm.account.login}}".
</div>
Javascript 文件 home.controller.js 如下所示:
(function() {
'use strict';
angular
.module('pruebablogApp')
.controller('HomeController', HomeController);
HomeController.$inject = ['$scope', 'Principal', 'LoginService', '$state', 'AlertService'];
function HomeController ($scope, Principal, LoginService, $state, AlertService) {
var vm = this;
vm.account = null;
vm.isAuthenticated = null;
vm.login = LoginService.open;
vm.register = register;
$scope.$on('authenticationSuccess', function() {
getAccount();
});
getAccount();
function getAccount() {
Principal.identity().then(function(account, $scope) {
vm.account = account;
vm.isAuthenticated = Principal.isAuthenticated;
if (vm.isAuthenticated){
$scope.show = true;
}
});
}
function register () {
$state.go('register');
}
function closeAlert () {
$scope.show = false;
}
}
})();
这种方法对我不起作用。我尝试了其他方法,例如this one 或this one(应该适用于按钮点击)。
我做错了什么?
【问题讨论】:
标签: javascript angularjs angular-ui-bootstrap jhipster