Reader small image

You're reading from  Getting Started with Angular - Second edition - Second Edition

Product typeBook
Published inFeb 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781787125278
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Minko Gechev
Minko Gechev
author image
Minko Gechev

Minko Gechev is a software engineer who strongly believes in open source software. He has developed numerous such projects including codelyzer, the AngularJS style guide, aspect.js and many others, and is one of the coauthors of the official Angular style guide.
Read more about Minko Gechev

Right arrow

Improving 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 again uses TypeScript. Do not worry if the syntax does not look familiar to you, we will make an introduction to the language in the next chapter.

The user class extends the EventEmitter class. This provides primitives for emitting and subscribing to events.

Now, let's define a...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Getting Started with Angular - Second edition - Second Edition
Published in: Feb 2017Publisher: PacktISBN-13: 9781787125278

Author (1)

author image
Minko Gechev

Minko Gechev is a software engineer who strongly believes in open source software. He has developed numerous such projects including codelyzer, the AngularJS style guide, aspect.js and many others, and is one of the coauthors of the official Angular style guide.
Read more about Minko Gechev