Services in Anjularjs
Till now we seen 2
built in services($http/remote requests, $log(logging object to console). Now
more information about services.
Services contains business logic it can be any type of service(WCF,WEB API,
WEB SERVICES..ect) same as in anjular also. If we need a logic it should be reuseable in many
places of anjular application we should write them as anjular services.
Controller has responsiable for building/prepares an object for model.
as per SOLID principal it should has a single responsiability only.
Example : if data
has dateofbirth ---need to compute ---age. We can do it in controller but SOLID
violation so that write as service. à we can utilize many
places of anjular application.
anjularjs service is an object.
anjularjs service encapsulate the logic that doesn’t belongs to anywhere else
(i.e Controllers, Directives,Filters,Views,Models)
Advantages:
Reuseability
Dependence Injections
Testability.
No comments:
Post a Comment