David
David

Reputation: 16038

Angular2 "Output" callback

I have a component which has an Event Emitter as follows:

@Output() onLoadRequired: EventEmitter<any> = new EventEmitter<any>();

This would be used something like:

<my-component (onLoadRequired)="loadStuff()" />

Where the loadStuff method returns a Promise<any>.

I need the my-component to know when the loadStuff promise has been resolved. How can this be achieved?

Upvotes: 2

Views: 741

Answers (1)

G&#252;nter Z&#246;chbauer
G&#252;nter Z&#246;chbauer

Reputation: 657416

If you make loadStuff() return a Promise this should work:

<my-component #mycomponent (onLoadRequired)="loadStuff().then(val => mycomponent.done()" />

done() in <my-component> is called when the promise resolves.

(not tested)

Upvotes: 2

Related Questions