Generating and capturing custom events using EventEmitter

In the wake of the disappearance of $scope, Angular was left with a void for propagating information up the component tree. This void is filled in part by custom events, and they represent the Yin to the downward data binding Yang.

Note

The code, links, and a live example of this are available at http://ngcookbook.herokuapp.com/8611/.

Getting ready

Suppose you had an Article application as follows:

[app/text-editor.component.ts] import {Component} from '@angular/core'; @Component({ selector: 'text-editor', template: ` <textarea></textarea> ` }) export class TextEditorComponent {} [app/article.component.ts] import {Component} from '@angular/core'; @Component({ selector: 'article', template: ` ...

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.