Skip to content

Instantly share code, notes, and snippets.

@mohamed-gara
Created July 1, 2018 10:33
Show Gist options
  • Save mohamed-gara/68c8d52bf508a0e05b8dac77df33f298 to your computer and use it in GitHub Desktop.
Save mohamed-gara/68c8d52bf508a0e05b8dac77df33f298 to your computer and use it in GitHub Desktop.
two-ticks-are-triggered
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