I have created an Angular component like p-overlaypanel but it is staying open for every item I click, I want if I click another overlay panel the last clicked should be hidden, I wan'T only one to be clicked and show not everyone of them Below you can find code in stackblitz.
https://stackblitz.com/edit/angular-yrsyt6?file=src/app/app.component.ts
Here is the code
<div class="dropdown">
<div class="body">
<ng-content select="[body]"></ng-content>
</div>
<div *ngIf="active" class="popup">
<ng-content select="[popup]"></ng-content>
</div>
</div>
.dropdown {
position: relative;
display: inline-block;
}
.popup {
display: block;
position: absolute;
z-index: 1000;
}
export class OverlaypanelComponent implements OnInit {
active = false;
constructor() {
}
ngOnInit() {
}
@HostListener('document:click', ['$event']) clickedOutside($event) {
this.active = false;
}
toggle($event) {
$event.preventDefault();
$event.stopPropagation();
this.active = !this.active;
}
close() {
this.active = false;
}
}