Angular 2: Convert Observable to Promise

后端 未结 7 663
耶瑟儿~
耶瑟儿~ 2020-11-27 18:00

Q) How do I convert the following observable to a promise so I can call it with .then(...)?

My method I want to convert to a promise:

7条回答
  •  攒了一身酷
    2020-11-27 18:09

    You can convert Observable to promise just by single line of code as below:

    let promisevar = observable.toPromise()
    

    Now you can use then on the promisevar to apply then condition based on your requirement.

    promisevar.then('Your condition/Logic');
    

提交回复
热议问题