I notice that when I have some elements under ngIf*, on ngOnInit() those elements don't exists even when the condition is met. How can I "catch" the moment when an element that is under ngIf* is rendered (I need to call some function on it)
Asked
Active
Viewed 734 times
0
-
you can use `afterViewInit` and read more about life cycle here https://angular.io/api/core/AfterViewInit – Abdul Basit May 06 '20 at 10:10
2 Answers
0
use ngAfterViewInit()
ngAfterViewInit() is called after a component's view, and its children's views, are created. Its a lifecycle hook that is called after a component's view has been fully initialized.
export class AfterViewInitDemoComponent implements AfterViewInit {
ngAfterViewInit() {
console.log("---ngAfterViewInit() Demo---");
}
}
please check following links for more info
https://angular.io/api/core/AfterViewInit
https://www.concretepage.com/angular/angular-ngafterviewinit

Shlok Nangia
- 2,355
- 3
- 16
- 24
0
If you use @ViewChild, try to use static: true
parameter.
@ViewChild('myElem', { static: true }) myElem: MyElementType;

Muhammet Can TONBUL
- 3,217
- 3
- 25
- 37