Best way to refresh a navbar?

632 views
Skip to first unread message

t...@livethelook.com

unread,
Sep 15, 2013, 5:00:58 AM9/15/13
to ang...@googlegroups.com
Hey, all. I have a navbar (Bootstrap 3, but no angularUI-bootstrap involved), and a couple of the navbar items in the dropdown are conditionally displayed based on the presence/absence of a 'user' object stored in the $rootScope. When selected, a user dialog asks the user for creds, and I send them off to the authentication server for a response, and the results come back asynchronously.

I'm looking for a 100% sure-fire way to update the navbar contents when the user object comes back. I've tried $rootScope.$apply, but that seems to periodically come back with a "$apply already in effect" error, and when I don't do $apply, it doesn't seem like the navbar is always being updated.

Very open to suggestions here....

Grant Rettke

unread,
Sep 15, 2013, 8:09:03 AM9/15/13
to ang...@googlegroups.com
Perhaps a basic directive just so that you don't have to call apply yourself.
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to angular+u...@googlegroups.com.
> To post to this group, send email to ang...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular.
> For more options, visit https://groups.google.com/groups/opt_out.



--
Grant Rettke | ACM, AMA, COG, IEEE
gre...@acm.org | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson

Ted Neward

unread,
Sep 15, 2013, 8:54:45 AM9/15/13
to ang...@googlegroups.com, ang...@googlegroups.com
Not sure what you mean; what would the directive do?

Ted Neward | CTO
m: (425) 647-4526 | e: t...@livethelook.com | t: @tedneward

Alexander Karelas

unread,
Sep 15, 2013, 10:47:33 AM9/15/13
to ang...@googlegroups.com
There's two ways:

One is to use $timeout (i.e. instead of $rootScope.$apply(function() {
... }), do $timeout(function() { ... }) )

Another way is to use safeApply (look at the first comment of this
blogpost - if you copy it exactly as is, it will create the safeApply
method for you: https://coderwall.com/p/ngisma )

- Alex
Reply all
Reply to author
Forward
0 new messages