Angular 2: Convert Observable to Promise

后端 未结 7 667
耶瑟儿~
耶瑟儿~ 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:26

    The proper way to make Observable a Promise, in your case would be following

    getAssetTypesPromise() Observable {
      return new Promise((resolve, reject) => {
          this.getAssetTypes().subscribe((response: any) => {
            resolve(response);
          }, reject);
        });
    }

提交回复
热议问题