Search code examples
angularpromisecomponentseventemitter

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?


Solution

  • 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)