2017-04-06 102 views
0

我最近发现并开始在JHipster中开发。如何自动关闭JHipster的提醒?

我面临的第一个障碍之一是自动关闭警报。到目前为止,我已经了解到,JHipster使用Bootstrap UI alerts,所以我想,当用户试图登录(绿色的),以适应在sample project of JHipster捆绑警报,这是在主页显示:

enter image description here警报

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> 

Javascri PT文件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 onethis one(它应该适用于按钮点击)。

我在做什么错?

回答

1

JHipster是为了创造出你想要创建(如信息,警告,危险等)消息类型使用AlertService作为一种服务,并显示与标签的消息。查看示例应用程序中的实体以查看标签jhi-alert的实际操作。您只需在html网站中写入标签,并使用AlertService在控制器中创建要创建和显示的消息。

@GaëlMarziou你的回答更深入到幕后实际发生的事情。我可以看吗?

+0

感谢您的回答。我只是尝试这样做: _controller:_ 'AlertService.warning( “你好,我是一个警报。”);' _View:_ '' 我得到这个从要素Chrome Debug中的检查器: '

' 尚未显示警报。有些东西还是错的。 – wickedchild

+0

尝试一口吞干净的构建。如果您正在编辑示例应用的其他实体,例如标签或BankAccount,您是否收到警报?例如,当您创建或编辑实体时,您应该会收到一条信息警报。 – duderoot

+0

的确,我收到了这些提醒。试图重建整个项目,没有任何改善。试图立即使用AngularJS警报。谢谢您的帮助! – wickedchild