Ngshow On $parent Variable?
I've got something running in the $rootScope to set an application-wide value for userLoggedIn: mod.run(function($rootScope) { $rootScope.userLoggedIn = false; $rootScope.
Solution 1:
The answer was unbelievably simple, and leveraged a comment too. I did in fact just need the view to use $root.userLoggedIn
, but I also needed to leverage the $apply
:
mod.run(function($rootScope) {
$rootScope.userLoggedIn = false;
$rootScope.$on('loggedIn', function(event, args) {
$rootScope.$apply(function() {
$rootScope.userLoggedIn = true;
});
});
});
Solution 2:
scope: { userLoggedIn: '@' }
Your directive expects the HTML attribute userLoggedIn
, but there is none in your HTML. Also keep in mind that @
always resolves to a String
.
The second and more important point is that only your root-scope
directive operates in the isolate scope, but not ng-show
. In other words: Using root-scope
has no effect whatsoever. Based only on the code you presented, your example works as expected.
Post a Comment for "Ngshow On $parent Variable?"