如何从angular2-modal中返回结果,或者一般地说,从ng2-components中返回结果?

6
我是这个伟大的angular2-modal的用户,但是我无法弄清如何从我的自定义模态窗口中返回结果值。
我像这样实例化它:
    let dialog: Promise<ModalDialogInstance>;
    let bindings = Injector.resolve([
        provide(ICustomModal, { useValue: this.gewaehltesBild })
    ]);
    var self = this;
    dialog = this.modal.open(
        <any>ImagecropperComponent,
        bindings,
        new ModalConfig("md", true, 27));


    dialog.then((resultPromise) => {
        return resultPromise.result.then((result) => {
            this.lastModalResult = result;
            this.mitarbeiter.avatarImg = this.gewaehltesBild;

            $(self.elementRef.nativeElement).find('#bildSelector').val("");
        }, () => this.lastModalResult = 'Rejected!');
    });

我尝试使用以下方式发送返回值:

this.dialog.close(this.croppedImage);

但结果始终为null。在Angular2中,是否存在一种约定用于从组件返回值,并被angular2-modal使用?

谢谢!

1个回答

8

对我而言运行良好,我也正在使用自定义对话框,以下是我如何捕获结果

  var dialog = this._modal.open(VideoPlayerComponent,
      resolvedBindings,
      new ModalConfig('lg', true, 27));
    dialog
      .then((d) => d.result)
      .then((r) => { console.log(r);  }, (error) => { console.log(r); });

当我在该实例上调用close时。
this._dialog.close("Hello");

它会打印出Hello


它可以工作,我认为在模态框内生成返回值的方法中有一个打字错误... :/ 谢谢 - Weissvonnix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接