Refactor Angular Controller Logic to Services

Share this video with your friends

Send Tweet

In Angular, we want to keep our controllers lightweight and specific to the view that it is controlling. To accomplish this, we are going to refactor our categories collection into a CategoriesModel. A recurring theme in Angular 2 is that everything is "just a class". When we create our controllers and services in an Angular 2 style, they are also "just a class". We will see this in action as we convert our controller almost verbatim into a service.

Stanislav
Stanislav
~ 8 years ago

Hi, what is the advantage of CategoriesModel being a service of CommonModule instead of CategoriesModule?

Lukas Ruebbelke
Lukas Ruebbelke(instructor)
~ 8 years ago

Hi Stanislav -- I like to break out services that are used by multiple components into a common module so that I can spin up one component without having a hard dependency on another component.