What is the difference between a component and a service?

Angular basics · Freshers

Model answer

A component controls part of the screen: it has a template (HTML), styles and a class with data and event handlers. A service is a plain class for logic that is not tied to one screen, such as calling an API, keeping shared state or logging.

Keeping this logic in services means several components can share it and it is easy to test. Components get services through dependency injection.

Tips

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions