use $rootScope in template

13,219 views
Skip to first unread message

war...@gmail.com

unread,
Nov 15, 2012, 6:19:03 AM11/15/12
to ang...@googlegroups.com
Hi,
I have an application where an easy access to $rootScope would be desired. Since $rootScope is not available in templates, normally I would assign particular variables to $rootScope using a controller.

But since this produces spaghetti code in the controller, I found a much shorter way to enable all $rootScope inside the template (without a need for the controller). Basically what I do is I assign $rootScope to $rootScope in module bootstrap. You can see it in action here: http://jsfiddle.net/wgtA6/

Can you please review this jsFiddle and tell me what do you think? Is it likely to kill the performance in the long run?

Peter Bacon Darwin

unread,
Nov 15, 2012, 7:36:22 AM11/15/12
to ang...@googlegroups.com
Try $root.namehttp://jsfiddle.net/wgtA6/1/

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en.
 
 

Marcin Warpechowski

unread,
Nov 15, 2012, 7:44:24 AM11/15/12
to ang...@googlegroups.com
Amazing, thanks! 

Is that mentioned somewhere in API Reference? I never saw it.

Peter Bacon Darwin

unread,
Nov 15, 2012, 7:47:57 AM11/15/12
to ang...@googlegroups.com
Can't find it!
Reply all
Reply to author
Forward
0 new messages