Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This question is addressed in the <a href="http://docs.angularjs.org/misc/faq" rel="nofollow noreferrer">AngularJS FAQ</a> quoted here:</p> <blockquote> <p>Occasionally there are pieces of data that you want to make global to the whole app. For these, you <strong>can inject $rootScope</strong> and set values on it like any other scope. Since the scopes inherit from the root scope, these values will be available to the expressions attached to directives like ng-show just like values on your local $scope.</p> </blockquote> <p>It seems that the team does encourage using <code>$rootScope</code> this way, with this caveat:</p> <blockquote> <p>Of course, global state sucks and you should use $rootScope sparingly, like you would (hopefully) use with global variables in any language. In particular, don't use it for code, only data. If you're tempted to put a function on $rootScope, it's almost always better to put it in a service that can be injected where it's needed, and more easily tested.</p> <p>Conversely, don't create a service whose only purpose in life is to store and return bits of data.</p> </blockquote> <p>This does not put too much load on the <code>$digest</code> cycle (which implements basic dirty checking to test for data mutation) and this is not an odd way to do things.</p> <p><strong>EDIT:</strong> For more details on performance, see this answer from Misko (AngularJS dev) here on SO: <a href="https://stackoverflow.com/questions/9682092/angularjs-how-does-databinding-work/9693933#9693933">How does data binding work in AngularJS?</a> Specifically note the section on performance. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload