Created
April 5, 2024 11:35
-
-
Save space11/f894b3b81e871004108c922ac7d37520 to your computer and use it in GitHub Desktop.
Allow only one ngx-bootstrap Popover at the time.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<button | |
type="button" | |
class="btn btn-default btn-secondary" | |
popover="Vivamus sagittis lacus vel augue laoreet rutrum faucibus." | |
popoverTitle="Popover on top" | |
placement="top" | |
> | |
Popover on top | |
</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ViewChildren, QueryList, AfterViewInit } from '@angular/core'; | |
import { PopoverDirective } from 'ngx-bootstrap/popover'; | |
@Component({ | |
selector: 'demo-popover-four-directions', | |
templateUrl: './four-directions.html' | |
}) | |
export class DemoPopoverFourDirectionsComponent implements AfterViewInit{ | |
@ViewChildren(PopoverDirective) popovers: QueryList<PopoverDirective>; | |
ngAfterViewInit() { | |
// NOTE: Rember to take care of unsubscribing when component / directive is destroyed | |
this.popovers.forEach((popover: PopoverDirective) => { | |
popover.onShown.subscribe(() => { | |
this.popovers | |
.filter(p => p !== popover) | |
.forEach(p => p.hide()); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment