Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AregSargsyan/d8d2e0fbff1324877844d06fb5da2e8a to your computer and use it in GitHub Desktop.
Save AregSargsyan/d8d2e0fbff1324877844d06fb5da2e8a to your computer and use it in GitHub Desktop.
ngAfterViewInit with changedetectorref
import { Component, ChangeDetectorRef } from '@angular/core';
@Component({
selector: 'app-child',
template: `<span>{{count}}</span>`,
})
export class ChildComponent {
count = 0;
constructor(private cd: ChangeDetectorRef) { }
increaseCount() {
this.count = 1;
}
ngAfterViewInit() {
this.increaseCount()
this.cd.detectChanges() // force change detection manually
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment