My question is about angular change detection and zonejs: is zonejs used by the (click)
event below?
@Component({
template: `
<button (click)="changeName()">Change name</button>
<p>{{ name }}</p>
`
})
export class AppComponent {
name = 'John';
changeName() {
this.name = 'Jane';
}
}
The reason behind my question is that most of the examples given to illustrate the purpose of zonejs mention setTimeout
or http calls but seldom plain (click)
events such as above.
edit: any tip to set breakpoints in relevant parts of the zonejs source code will be greatly welcome.
According to their README, zone.js
patches web APIs, which also included DOM events. They also have a full list of events which includes click
events. For zone-based applications this is necessary for Angular to know when the view needs to be updated.
So the answer to your question is: Yes, zone.js
is used in this example. (unless your application is using zoneless change detection)