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

时间:2018-08-27 21:40:30

标签: angular dialog parent

我有一个有角的DialogueService,它会打开一个弹出窗口,该弹出窗口有一个字段,一旦单击“是”,必须捕获其文本,我该如何将值从dialogservice传递回父级

  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();
  }
  }

2 个答案:

答案 0 :(得分:0)

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

请参考此链接: Delegation: EventEmitter or Observable in Angular

答案 1 :(得分:0)

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

相关问题