Configuring components to use explicit change detection with OnPush

The convention of Angular's data flow, in which data flows downward through the component tree and events float upwards, engenders some interesting possibilities. One of these involves controlling when Angular should perform change detection at a given node in the component tree.

Note

The code, links, and a live example related to this recipe are available at http://ngcookbook.herokuapp.com/4909/.

Getting ready

Begin with the following simple application:

[app/root.component.ts] import {Component} from '@angular/core'; import {Subject} from 'rxjs/Subject'; import {Observable} from 'rxjs/Observable'; @Component({ selector: 'root', template: ` <button (click)="shareSubject.next($event)">Share!</button> ...

Get Angular 2 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.