Skip to content

Instantly share code, notes, and snippets.

@mohamed-gara
Created July 1, 2018 10:21
Show Gist options
  • Save mohamed-gara/716f4d0c58da095c327de24da3804920 to your computer and use it in GitHub Desktop.
Save mohamed-gara/716f4d0c58da095c327de24da3804920 to your computer and use it in GitHub Desktop.
a-single-tick-is-triggered
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