Created
July 1, 2018 10:21
-
-
Save mohamed-gara/716f4d0c58da095c327de24da3804920 to your computer and use it in GitHub Desktop.
a-single-tick-is-triggered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, DoCheck } from '@angular/core'; | |
@Component({ | |
selector: 'app', | |
template: ` | |
<h3>On each button click a single ApplicationRef.tick() is triggered</h3> | |
<div>Counter: {{ counter }}</div> | |
<div> | |
<button (click)="increment()">Increment</button> | |
<button (click)="decrement()">Decrement</button> | |
</div>`, | |
styleUrls: ['./app.component.css'] | |
}) | |
export class AppComponent implements DoCheck { | |
counter = 0; | |
increment() { | |
this.counter++; | |
} | |
decrement() { | |
this.counter--; | |
} | |
ngDoCheck() { | |
console.log('Angular change detection cycle is running.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment