0

I have recently discovered and started to develop in JHipster.

One of the first hurdles I'm facing is to close automatically alerts. So far, I have learned that JHipster uses Bootstrap UI alerts, so I'm trying to adapt the alerts bundled in the sample project of JHipster, which are shown in the Home when the user tries to log in (the one in green):

enter image description here

HTML code for alerts was as follows:

        <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>

Which I modified such as this:

            <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 file home.controller.js looks like this:

(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 method is not working for me. I've tried other approaches, such as this one or this one (which should work for button clicks).

What am I doing wrong?

Community
  • 1
  • 1
xabi_sides
  • 335
  • 3
  • 20

1 Answers1

1

JHipster is using AlertService as a service in order create the messages type which you want to create (e.g. info, warning, danger etc.) and the message is displayed with the tag. Have a look at the entities in the sample app to see the tag jhi-alert in action. You just write the tag in the html site and you create in your controller with AlertService the message which you want to create and display.

@Gaël Marziou your answer was more into deep of what is actually happening behind the scene. Can I see it?

duderoot
  • 977
  • 1
  • 8
  • 23
  • Thanks for your answer. I just tried this: _Controller:_ `AlertService.warning("Hi, I'm a warning alert.");` _View:_ `` I get this from the elements inspector in Chrome Debug: `` Yet no alert is being shown. Something is still wrong. – xabi_sides Apr 07 '17 at 08:44
  • try a gulp clean build. If you are editing the other entities of the sample-app, e.g. Label or BankAccount, are you receiving the Alerts? For example when you are creating or editing an entity you should receive a info alert. – duderoot Apr 07 '17 at 09:50
  • Indeed, I'm receiving those alerts. Tried to rebuild the entire project, no improvement whatsoever. Trying to use AngularJS alerts right now. Thanks for the help! – xabi_sides Apr 10 '17 at 08:25