1

I have forEach loop that hides an HTML element after 10 sec. I've put it inside a setTimeout function but it's not waiting for 10 sec, the element is hiding with page load. Not sure if it is because of Angulars lifecycle looks or forEach loop.

Here is my typescript code

ngAfterViewChecked() {  
    if(this.on) {  
      this._notificationsElements.forEach((element) => {      
        const htmlElement = element.nativeElement as HTMLElement;
        setTimeout(htmlElement.setAttribute("style", "display:none;"), 10000);
      });
    }
  }

1

1 Answer 1

4
setTimeout(htmlElement.setAttribute("style", "display:none;"),10000);

needs to be:

setTimeout(() => htmlElement.setAttribute("style", "display:none;"),10000);

setTimeout requires a function.

Sign up to request clarification or add additional context in comments.

1 Comment

That being said, hiding it like this is a pretty dirty way of doing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.