How to return the result from an angular2-module or generally from ng2-components

I am using this big angular2-modal but cannot figure out how to return the result value from my custom modal code.

I create 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 tried sending my return value using

 this.dialog.close(this.croppedImage); 

but the result is always zero. Is there a convention in angular2 how to return values ​​from components that are used by angular2 -modal?

Thanks!

+6
source share
1 answer

Works well for me, I use a custom dialog too, and this 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 an instance

 this._dialog.close("Hello"); 

He prints Hello

+8
source

All Articles