Search code examples
javascriptaurelia

javascript settimeout function in aurelia


I want to hide an element after some time ( about 2 seconds ). in javascript in can use setTimeout function for that. Is there a way that I could use it on Aurelia? or is there a better way for this?


Solution

  • You can hide the element using the if custom attribute included in Aurelia. Then bind that to a property on the viewmodel.

    this.showItem = true;
    window.setTimeout(() => this.showItem = false, 2000);
    
    <h1 if.bind="showItem">I will hide in 2 seconds</h1>