Otto, That's an excellent question. Avoid injecting the model to $rootscope as that would increase unnecessary overhead all over the app. Instead, create a reusable service and use where it is needed. The good candidates for $rootscope are: 1. User Logged-in info. 2. Device/ Browser/ Orientation detection 3. httpSessionTimedOut global handler 4. $routeChangeStart, $routeChangeSuccess & $routeChangeError global handler 5. Global app search
Regards Rishi Tandon On Mon, Sep 15, 2014 at 10:18 AM, Otto Wong <[email protected]> wrote: > hi there.. i'm semi-new to angularjs, ie, i've been using it for a while > now but i have no clue if what i'm building is against best practices or > not! :) > > i'm coming to a point in my application where it's becoming apparent due > to changes in requirements that certain features should have been done by > creating a service, since multiple different places in the application are > needing to do the same thing. > > a while back, i needed to open modals. this type of requirement is very > easy to identify as "something that requires multiple places to do the same > thing". back then, i was less familiar with services and factories and > solved this problem by creating a function defined in the $rootScope, so > every time i need to open a modal now, i include $rootScope in the > controller that needs it and open it with a function that goes something > like $rootScope.modal('open',url);, and close it with > $rootScope.modal('close',''); > > is this way of doing it wrong or against best practices? i'd like to know > if there is a performance difference between creating a service and just > defining a lot of $rootScope functions? > > thanks! > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/d/optout. > -- *Rishi Tandon* Pearson Learning Technology Group Mobile: (310) 926-9032 Pearson Always Learning Learn more at www.pearson.com -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
