Created
June 7, 2020 12:24
-
-
Save AregSargsyan/d8d2e0fbff1324877844d06fb5da2e8a to your computer and use it in GitHub Desktop.
ngAfterViewInit with changedetectorref
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, 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