【发布时间】:2018-12-19 07:47:22
【问题描述】:
我创建了一个类似于 OverlayPanel 的组件,因此我可以在其中进行更多点击或其他操作。 但是当我在覆盖层之外或在覆盖层中单击时,它不会退出总是在那里,只有当我单击我所写的按钮时它才会消失。
Here is the link of the StackBlitz
我喜欢这样创建的overlaPanel。
<div class="dropdown">
<div (click)="toggle()" 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() {
}
offClickHandler(event: any) {
if (event['.body'] && event['.popup'] === true) {
this.active = false;
}
}
ngOnInit(): void {
}
toggle() {
this.active = !this.active;
}
close() {
this.active = !this.active;
}
}
这是我调用这个组件的时候
<app-overlaypanel>
<div body [ngClass]="[getBackgroundColorClass(),clazz]" class="fa fa-pencil-square-o edit-block"></div>
<div class="overlayPopup" popup>
<div class="dropdown-menu-item" (click)="openTechnicalEditDialog({cluster: cluster, type: clazz})">Edit</div>
<div class="dropdown-menu-item" (click)="delete()">Delete</div>
<div class="dropdown-menu-item" (click)="openTechnicalEditDialog({appendToParentId: cluster.id})" *ngIf="cluster.level <= 9">Append</div>
<div
class="dropdown-menu-item" (click)="clicked.emit()">Assign</div>
</div>
</app-overlaypanel>
【问题讨论】:
-
你能在stackblits中添加你的代码吗
-
@Chellappan 我会尝试,但我在堆栈闪电战中表现不佳
-
@Chellappan 这是我创建的堆栈闪电战。 stackblitz.com/edit/angular-rfvmjl
标签: html css angular typescript