如何将值从对话框服务传递到父角度 2



我有一个角度对话框服务,它会打开一个弹出窗口,弹出窗口有一个字段,单击"是"后必须捕获其文本,如何将值从对话框服务传递回父级

this.popupservice.addDialog(Component,
{
title: 'Confirmation',
message: 'test'
})
.subscribe((isConfirmed) => {
if (isConfirmed) {
// catch returnText here
return true;
} else {
return false;
}
});
export interface CompModel {
title: string;
message: string;
returnText: string;
}                
export class Component extends
PopupComponent<CompModel, boolean>{
implements CompModel {
title: string;
message: string;
returnText: string
confirm() {
// send return from here
this.close();
}
}

简单地说,您可以在服务层中使用 EventEmitter 并从服务接收任何事件。

请参考此链接 : 委托:事件发射器或角度可观察

您可以在close()方法中将该值作为参数传递,并且可以在subscription中访问此值。请查看文档。

最新更新