angularangular-animations

Display a div only for few seconds in Angular


I want to display a notification on angular app only for few seconds, the event is triggered after clicking a button.


Solution

  • how about this:

    html

    <button (click)="showDiv()">Click</button>
    <div *ngIf="!hideDivFlg">My Div</div>
    

    .ts

    showDiv() {
        this.hideDivFlg = false;
        setTimeout(() => {
          this.hideDivFlg = true;
        }, 4000);
    }