My 2c is 1 and part of 2.

The nice thing about promises is they can have multiple 'then' so both your 
option 1 and the first part of option 2 can be used - they aren't mutually 
exclusive.
Also, there is no reason why there can't be two levels of promise. Eg. I 
use the $http promise, but that isn't the promise that I return to the 
application layer. I have a separate app-layer promise. In my case that 
allows me to do things like error handling and pagination invisibly to the 
controller.

I avoid broadcasts - too hard to debug.


On Wednesday, 2 December 2015 18:22:45 UTC, Jonathan Price wrote:
>
> I've got a number of services that are basically collection clearing 
> houses for certain types of objects.  I'm wondering how it's generally 
> preferred to handle the following:
>
> I've got a ContactService and a ContactPageController, let's say.  All 
> remote fetching is handled in the service.  I want to initiate a remote 
> fetch from the controller.  Do I:
>
> 1) Have the service return a promise and let the controller handle letting 
> other controllers/services know there has been an update?
> 2) Let the service deal with it's own promise and broadcast some kind of 
> 'collectionUpdated' event?
>
> Just curious if there's a best practice suggestion for this?  I'm 
> currently leaning on #2.
>
> 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.

Reply via email to