Currently, I am utilizing Angular 2 (TS) and in need of some assistance:
constructor(public element:ElementRef){}
ngOnInit(){
this.DOMready()
}
DOMready() {
if (this.element) {
let testPosition = this.element.nativeElement.getElementsByClassName("_mypost");
console.log(testPosition);
for (let i = 0; i < testPosition.length; i++) {
console.log(testPosition[i]);
}
} else {
setTimeout(this.DOMready, 100)
}
I am facing the following issues:
1) I am struggling to accurately determine when the document is fully loaded and ready for manipulation (I have tried using Angular 2 lifecycle Hooks without success)
2) When I use console.log(testPosition), it displays a list as expected with a length of 10. However, accessing individual elements such as console.log(testPosition[0]) returns undefined. Additionally, running console.log(testPosition[i]) produces no output.
Thank you in advance)