O'Reilly logo

Switching to Angular 2 by Minko Gechev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Change detection

As we saw earlier, the view in MVC updates itself, based on change events it receives from the model. A number of Model View Whatever (MVW) frameworks took this approach, and embedded the observer pattern in the core of their change detection mechanism.

Classical change detection

Let's take a look at a simple example, which doesn't use any framework. Suppose we have a model called User, which has a property called name:

class User extends EventEmitter {
  private name: string;
  setName(name: string) {
    this.name = name;
    this.emit('change');
	}
  getName(): string {
    return this.name;}
}

The preceding snippet uses TypeScript. Do not worry if the syntax does not look familiar to you, we're going to make an introduction to the language in the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required