Home > Enterprise >  How to close popover after certain interval in Angular?
How to close popover after certain interval in Angular?

Time:07-31

I am using Angular(14) and ngxbootstrap(https://valor-software.com/ngx-bootstrap/#/components/popover?tab=overview). I am unable to see closing the popover automatically after certain interval. It has show()/hide() functions but how do we achieve this? Show the popover and close after certain interval?

CodePudding user response:

According to the documentation of ngx-bootstrap you can use the isOpen attribute to close the popover.

Using the example provided in their documentation:

<p>
  <span popover="Hello there! I was triggered by changing isOpen property"
    triggers=""  [isOpen]="isOpen">
    This text has attached popover
  </span>
</p>
<button type="button" 
  (click)="isOpen = !isOpen">
  Toggle
</button>

You could bind a function to the click event that would trigger a timeout to close you popover:

Add the onPopOverClick method in the .html file:

<button type="button" 
  (click)="onPopOverClick()">
  Toggle
</button>

And in the .ts file:

onPopOverClick(): void {
  this.isOpen = true;
  setTimeout(() => {
    this.isOpen = false;
  }, 5000); // the delay before popover closes automatically
}
  • Related