Component:
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
//name = 'Angular';
onClick(){
//this.name = 'hey';
}
check(){
console.log('wow');
}
}
Template:
<button (click)="onClick()">Click</button>
{{check()}}
When I run this, 'wow' gets printed on the console initially 4 times (not sure why 4 times, but let's leave that). The main thing is that when I click on the button, 'wow' gets printed (twice) even though I have changed nothing in the template expressions.
As I understand it, when an event, etc occurs, change detection takes place which compares fields used in expressions and property binding in template. If a change is detected, the view is re-rendered. But in this case, the view is being re-rendered (as shown by the calling of check method) even when no change should have been detected
Stacklitz here