Can you explain the significance of the change
event in Angular 2? When does it occur and how is it utilized?
For example, what action am I subscribing to in the code snippet (change)="update()"
?
import {Component, View, Input, Output, EventEmitter, OnChanges} from '@angular/core'
@Component({
selector: 'inner-component',
template: `
<label><input type="checkbox" [(ngModel)]="data.isSelected"> Selected</label>
`
})
export class InnerComponent {
data = { isSelected: false };
}
@Component({
selector: 'my-app',
template: `
<p><inner-component (change)="update()"></inner-component></p>
<p>The component was updated {{count}} times</p>
`,
directives: [InnerComponent]
})
export class AppComponent {
count = 0;
update() {
++this.count;
}
}