Home > database >  How to create an event that lasts for some time?
How to create an event that lasts for some time?

Time:08-01

For example, I have a div:

<div [hidden]="!isNotificationDisplayed" >
  <h2 align="center"  #notification>Node was...!</h2>
  <h4 align="center">Press 'Space' to hide it</h4>
</div>

isNotificationDisplayed is a variable whose value (true/false) determines whether this div will be displayed or not. By default, it is set to false, meaning the div is not displayed. I want to make a function that sets true for 3 seconds, i.e. the div is visible for 3 seconds, after which it is reset to false.

CodePudding user response:

setTimeout(() => {
    this.isNotificationDisplayed = true;
  }, 3000);
  • Related