0
Angular · Angular Services
New technique
Why services?
A smith at the anvil shouldn't also run the mine. Components show things; services do the heavy lifting behind them.
A service is a plain class that holds logic or data shared by several components: loading data from a server, keeping a shopping cart, logging, checking who is logged in.
Components stay small and focused on the screen. The service can be reused anywhere, and tested on its own. If two components need the same data, putting it in a service means they really share it, instead of each keeping its own copy.