AngularJs: ng - if it's too late to respond

Im using ui.router and turning on my navigation like this in my main html file:

<header ng-if-start="logedin()"></header> <navigation ng-if-end="logedin()"></navigation> 

boolean logical logedin() will be set via angular.module().run() in this function:

 $rootScope.$on('$stateChangeStart', function(e, to) 

If I exit on one of the navigation systems, the navigation controller will run this function:

 $scope.logout = function() { store.remove('jwt'); $state.go('login'); } 

Problems after $state.go not hidden, but after page refresh.

Do I need to redraw the main template / index view (and then how)? Or how can I solve this problem?

+8
javascript angularjs angular-ui-router
source share
2 answers

So I decided it myself. Sorry for the lack of the logedin () method.

The problem was this:

 $scope.logedin = function() { return $rootScope.logedin } 

$rootScope.logedin was installed in the angular.module().run() function.

To solve this problem, I had to create a simple getter / setter service.

 angular.module('sample') .service('sharedLogedIn', function () { var property = true; return { getProperty: function () { return property; }, setProperty: function(value) { property = value; } }; }); 
+4
source share

Good to know that the problem is resolved. What could happen, your values ​​are not propagated ... I can do this for troubleshooting:

 <header ng-if="loggedinBool"></header> <navigation ng-if="loggedinBool"></navigation> 

1) Assign a loggedin () value to the scope model or a service property (preferably) of loggedinBool and see if the values ​​are propagated after logging out, which changes the loggedinBool value.

2) If this does not work, try $ broadcast / $ emit in loggout and write this to change the value of loggedinBool. This should automatically provide a two-way binding to try using the $ scope.digest () or $ scope.apply () method to see if the values ​​are propagated.

+1
source share

All Articles