wonderful world
wonderful world

Reputation: 11599

How to add a delay in angular component?

I have an angular component inside a modal dialog. When the dialog is closed, I want to delay closing of the modal dialog.

How can I add delay for 5 seconds inside an Angular component before closing it?

Upvotes: 2

Views: 5910

Answers (2)

RajuPedda
RajuPedda

Reputation: 3389

One way you can delay your dialog is, by using timeOut, And you can also pass some information back to your modal dialog.

    onCloseClickHandler(e: any): void {
       setTimeout(() => {
      this.dialogRef.close(e);
    }, 5000);
  }

Upvotes: 0

yanky_cranky
yanky_cranky

Reputation: 1363

You can have an event handler like "onClose" in whatever dialog you are using and add delay in that, then close the modal.

Angular Material Dialog

 onNoClick(): void {
    setTimeout(()=>{
      this.dialogRef.close();
    },5000); 

  }

Upvotes: 2

Related Questions