Before proceeding to the next step, I have an observable that must be executed.
export class MyExample implements OnInit {
flag;
constructor(private myService: MyService) { }
myFunc() {
flag = 0;
this.myService.subscribe(data => {
this.consumeData(data);
this.flag = 1;
});
}
}
The instructions within the subscribe()
method may require a few seconds to complete. To handle this, I need to convert the init()
function into an async init()
. I introduced a flag
variable to indicate success, but I'm struggling to merge an Observable with an asynchronous function (or possibly just a promise).
In my Component, I aim to invoke init()
in this manner:
this.myFunc().then(() => console.log('ok'));