Reputation: 3318
I was wondering this:
Should we assign the commonly* used variables inside $rootScope
or should we declare them in a top-most parent ng-controller
?
Thank you
Upvotes: 0
Views: 192
Reputation: 117370
This is a question very similar to the Global variables in AngularJS
Generally speaking you should try to avoid putting things on a $rootScope
as it is AngularJS equivalent of a global window
scope. Since the $rootScope
can be injected everywhere (services, directives etc.) variables declared on the root scope a truly global.
If you've got a top-most, app-level controller and sticking variables in there does the trick for you I would favor this over polluting the $rootScope
. As a general rule of thumb we should be using the most restrictive / lower-level scope.
Don't forget that a service might be an answer here.
Upvotes: 3