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

Build Lightweight Controllers by Binding to Models in Angular

Build Lightweight Controllers by Binding to Models in Angular

10:02
In Angular, our controllers should be small and focused on the view that it is controlling. We accomplish this by moving as much logic and state as we can into models. Angular 2 introduced observables and async pipes which make it easy to manage state and communicate that directly to our templates. We can start to point our Angular 1 applications in that direction by binding to our models directly from within our controllers. In this lesson, we will see a simple example of this technique and a slightly more advanced case where we lose the lexical reference to the `this` keyword.
Watch this lesson now
Avatar
egghead.io

In Angular, our controllers should be small and focused on the view that it is controlling. We accomplish this by moving as much logic and state as we can into models. Angular 2 introduced observables and async pipes which make it easy to manage state and communicate that directly to our templates.

We can start to point our Angular 1 applications in that direction by binding to our models directly from within our controllers. In this lesson, we will see a simple example of this technique and a slightly more advanced case where we lose the lexical reference to the this keyword.

Avatar
Thom

Great course ! I want to use this approach to re-factor an existing NG1 app. What other references are good to use for making an angular 1 app angular 2 ish ?

Avatar
Lukas

Hey Thom,
You are in luck! I have actually created an Egghead course and companion guide on this very topic. See https://www.angular2patterns.com/ and https://egghead.io/courses/using-angular-2-patterns-in-angular-1-x-apps. Thanks!

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