user8334943
user8334943

Reputation: 1557

when to implement ng2 "services"?

What are the general decision rules around when to implement ng2 services? I'm fairly new to ng2 but I was thinking that they should just be used as a wrapper for external API calls. It seems like any other use could potentially be ambiguous and/or confusing. Technically, any isolation of logic into an encapsulated class could be considered a "service" but in that case I would simply put this logic into its own class without calling it a "service."

Upvotes: 0

Views: 44

Answers (1)

Arun Redhu
Arun Redhu

Reputation: 1579

Angular services are very helpful not just only writing wrapper for external api or something else but there are a number of use cases where services are very helpful. Some of the use case are described as:

  • Angular services can be used to communicate between components.
  • Angular services are likely to be singleton in nature.
  • Component should contains logic related to the view and other part should be written in services.
  • With the help of services we can share the same logic between different components.

Upvotes: 2

Related Questions