Tuesday 15 April 2014

javascript - AngularJS philosophy - controllers as "windows" to services -


Sorry for the obscure title;

I am trying to reconstruct some of my AngularJS codes, there are more "angular" about it, and I have noticed that this method is going a little bit popping up:

  app.service ("someService", function (...) {...} App.controller ("ControllerForThisSection", function ($ scope, someService) {$ scope.someService = someService}   

Actually, the controller is often mostly in the scope of the service, so a view can use it, such as

  
ng-if = "someService .status "& gt; .... & lt; / div & gt;

this I have some controllers who rely on some shared data or services and do nothing and provide service in the context of the services available through this service.

Is this design used No loss in doing

This "angular way" is to keep shared data in services Should be injected, where necessary, then.

(Who usually prefer are stored in services) and in terms of visuals to think about my angular apps. Controllers are the only glue that allows us to project / remove parts of our models that require a specific UI view.

Also, think of services as a model API return, not a model object (copy)

No comments:

Post a Comment