I am trying to select all pre elements in an angular component AFTER the document has been loaded.
ngAFterViewChecked, ngAfterContentChecked, ngAfterContentInit basically run 30 times before the document is loaded, which will slow down my app.
So, that leaves ngAfterViewInit, which logically one would think would work, but does not do anything because the document is not loaded yet. So, I am thinking an event listener as in vanilla js.
constructor(
@Inject(DOCUMENT) private document: Document,
private renderer: Renderer2
) { }
ngAfterViewInit(): void {
this.renderer.listen('document', 'load', (event) => {
console.log("loaded")
const pres = this.document.querySelectorAll('pre');
for (var i = 0; i < pres.length; ++i) {
console.log("Yes!");
}
});
}
This does not work as expected, but I have not seen any other methods quite try something this way, so I am thinking something similar could work.
Note: My pre tags are loaded asynchronously from a database in an [innerHTML]="content"
.
Any ideas?