Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return result from angular2-modal, or in general from ng2-components

I am using the this great angular2-modal but can't figure out how to return a result value from my custom modal.

I instantiate it like this:

    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!');
    });

I have tried to send my returnvalue with

this.dialog.close(this.croppedImage);

but result is always null. Is there a convention in angular2 how to return values from components, that is used by angular2-modal?

Thank you!

like image 533
Weissvonnix Avatar asked Apr 11 '16 22:04

Weissvonnix


1 Answers

Works fine for me, I too am using custom dialog and here is how i catch the result

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

When i call close on the instance

this._dialog.close("Hello");

It does print Hello

like image 154
Chandermani Avatar answered Sep 20 '22 13:09

Chandermani