The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Refactor Angular Controller Logic to Services

Refactor Angular Controller Logic to Services

3:28
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.
Watch this lesson now
Avatar
egghead.io

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.

Avatar
Stanislav

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

Avatar
Lukas

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.

In reply to Stanislav
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?