I guess the THINGCOLLECTIONSERVICE I'm talking about above would be a way 
to bundle business logic that relates to multiple services, right?


On Monday, October 13, 2014 12:53:55 PM UTC-7, Jonathan Price wrote:
>
> Below is a longer-winded way of asking if it makes sense to use a service 
> (or factory, rather) as a collection of resources from other services and 
> to maintain some kind of relationship status between these other services.  
> If that statement doesn't make sense on it's own, I cobbled together a 
> thought example below.
>
> ---
>
> Let's say I have a service that handles a couple of http calls for a 
> collection of THINGS and THINGCATEGORIES.  Something along these lines:
>
>     .factory('THINGS1', ['APIService',
>         function(APIService) {
>        
>         var model = {};
>
>         model.THINGS = [];
>         model.THINGCATEGORIES = [];
>
>         APIService.getTHINGS().then(function(THINGS) {
>             model.THINGS = THINGS.data;
>         });
>
>         APIService.getTHINGCATEGORIES().then(function(CATS) {
>            model.THINGCATEGORIES = CATS.data;
>         });
>
>         return {
>
>             getCategories: function() {
>                 return model.THINGCATEGORIES;
>             },
>
>             getThings: functino() {
>                 return model.THINGS;
>             }
>         }
>     }])    
>
>
> And let's say I've got a number of these kinds of services and they relate 
> hierarchically somehow.  A given page might need to know about 
> relationships between a few of these services and keep track of an active 
> state of some of these things.  As an example, say SERVICE1 (THINGS1) 
> hierarchically dictates which THINGS2 in SERVICE2 are shown on a page.  On 
> top of that, THINGS in SERVICE2 can be turned on an off through say a 
> directive, so someone needs to keep tabs of which THINGS2 in SERVICE2 are 
> active.
>
> And, let's say this particular configuration happens in two different 
> pages, so I'd like to build it as reusably as possible.  Would it make the 
> most sense to have a third service, say THINGCOLLECTIONSERVICE that pulls 
> in the THINGS from SERVICE1 and SERVICE2 and maintains the active states 
> for the page controllers?
>
> Or would it be better to have the active states maintained in a 
> controller?  My worry with that is that the controller might not be 
> strictly reusable in both pages where this is occurring.
>
> Or I guess I could just throw and active state array in the individual 
> services?
>
> Hopefully this makes sense.
>

-- 
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.

Reply via email to