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: ` <h1>{{title}}</h1> <p>Word count: {{wordCount}}</p> <...