Reputation: 125
Is there a way to wait for a HTML element to render after it has been enabled because of an *ngIf
?
StackBlitz to show what I mean exactly.
I can't do document.getElementById('someid')
if I just toggled the condition of the *ngIf
on an element. Is there a callback/way to call the code just after the element has been rendered?
I just want it called on a specific element, so I can't just use ngAfterViewChecked().
Upvotes: 2
Views: 7917
Reputation: 176
You can do html render first setting the function into a setTimeout
if(this.render) {
setTimeout( () => document.getElementById('someid').focus());
}
Upvotes: 3
Reputation: 1270
Check this blitz: https://angular-hwpfwx-xvmbiv.stackblitz.io Open the console to see the reference to the div.
It uses ViewChild
to detect the same div
using ngIf
.
Upvotes: -1