How to know when DOM is loaded?

17 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Frank Mehlhop

ungelesen,
19.03.2018, 08:16:3419.03.18
an Angular and AngularJS discussion
Hi,

at my angular app inside a compenent.ts I want to know when the DOM is ready loaded.
So I put inside the constructer following code:
window.addEventListener('load', function () {
console.log('DOM fully loaded and parsed !!!!!!!!!!!!!!!!!!!!!!!!!!!!');
}, false);

The log ""DOM fully loaded and parsed !!!!!!" 
is never called at the browser console.

Why it is not working?
How it should look like to get it work?

Frank

Sander Elias

ungelesen,
20.03.2018, 00:32:4120.03.18
an Angular and AngularJS discussion
Hi Frank,

Doing DOM manipulation with native methods like this is kind of an antipattern in Angular.
Aside from that, if you need to run some code after the template is parsed and read, you should use the ngAfterViewInit life-cycle hook.
Take into account that that is after the change-detection is done, and you can not manipulate data in there.

Regards
Sander
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten