0

I'm having trouble trying to reflect my changes in $rootScope. As I understand (please note that I'm very new to angular), $rootScope is visible across controllers. What I'm trying to do is to update a value in $rootScope and trying to read that value in my html page.

The problem is even though the changes are applied to $rootScope its not reflecting in my view. Following is the code

I have a div which I want to show/hide depending on the value

#view
<div ng-hide="{{logged}}">
  // this should visible only if the logged is true
</div>  



#controller1 I set the rootscope to false
$rootScope.logged = false; // this makes the view hidden


#controller2 I set the rootScope to true
$rootScope.logged = true; 
$rootScope.$apply();

But making the $rootScope.logged = true doesn't make the view visible. My questions are

1 - What I might be going wrong?

2 - What is the most Angular way of doing such a thing?

1
  • 2
    ng-hide="logged" ? Commented Dec 3, 2014 at 11:57

1 Answer 1

2

No need to use {{ in your html template.

#view
<div ng-hide="logged">
  // this should visible only if the logged is true
</div>

This is enough.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks it works, and I could removed the $rootScope.$apply() as well, all good now :)
You only need to use $apply if you are updating out of the angular context (if my knowledge serves correct) e.g jquery, if you're in a scope object you shouldn't need to call apply

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.