【发布时间】:2018-10-20 18:37:30
【问题描述】:
有两个组件List和Modal:
他们没有孩子-父母的关系。
问题是当您单击新按钮然后调用openModal() 方法时,您会打开弹出窗口。
我设置this.isOpenModal = true;
-
List Component openModal() 部分逻辑:
public isOpenModal: boolean = false; public openModal(id: string): void { if (!this.isOpenModal) { this.isOpenModal = true; const data = {id: id}; this.modalModel.add(AudienceModel.ENTITY_NAME, data); } }
在模态组件中我有 close() 方法:
isModalOpen: boolean;
public close(index: number): void {
this.isModalOpen = false;
this.audienceModel.isModalOpened = this.isModalOpen;
for (let i = 0; i < this.modalsArray.length; i++) {
if (this.modalsArray[index].modalStyle.zIndex <= this.modalsArray[i].modalStyle.zIndex) {
this.modalsArray[i].modalStyle.zIndex--;
}
}
this.modalsArray.splice(index, 1);
}
执行关闭方法时,我需要将其设置为 false:isOpenModal: boolean = false; 并在列表组件中提供该事件。
有什么解决办法吗?
【问题讨论】:
-
这个
close(index: number)方法是组件还是模型的一部分? -
ModalComponent 的一部分。
-
您应该使用充当这些组件之间的中介的服务,因此这些组件是松散耦合的。该服务负责显示和关闭模式。当模式关闭时,您可以使用此服务通过
RxJS Subject发出值。 -
如何使用 OpenModal 模式?在 ngIf 中?
标签: angular typescript