Created
July 1, 2018 10:33
-
-
Save mohamed-gara/68c8d52bf508a0e05b8dac77df33f298 to your computer and use it in GitHub Desktop.
two-ticks-are-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 two ApplicationRef.tick() are triggred</h3> | |
<div> | |
<div>Counter: <input [ngModel]="counter" #counterValue="ngModel"></div> | |
<div>Counter value: {{ counter }}</div> | |
<div>Exported value: {{ counterValue.value }}</div> | |
</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