skip to Main Content

I want to show this element only for 5 seconds and after that needs to remove from the dom.

{{#if canShow}}
  <div>
     This is block
  </div>
{{/if}}

Please help me to solve. I don’t know how to achieve this.

2

Answers


  1. If you are in an Ember component you can use:

    init() {
      Ember.run.later(() => {
        this.set('canView', false) // Or you can toggleProperty here
      }, 5000);
    }
    Login or Signup to reply.
  2. You could create a modifier that, when added to an element, will remove the element from the DOM after a certain period of time.

    First install ember-modifier (this is installed by default in new Ember projects): ember install ember-modifier

    Then create a new modifier ember g modifier remove-after.

    // app/modifiers/remove-after.js
    
    import { modifier } from 'ember-modifier';
    
    export default modifier(function removeAfter(element, [delay]) {
      setTimeout(() => {
        element.remove();
      }, delay);
    });
    
    <div {{remove-after 3000}}>Will be removed after 3 seconds</div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search