Angular2解决订阅中的承诺?

时间:2017-03-08 19:27:23

标签: angular promise resolve subscribe

有没有办法让这个伪代码工作?

private letsSee(): Promise<any> {
  return new Promise(resolve => {
    this.someService.someValue.subscribe((nextValue) => {
      resolve(nextValue);
    });
  });
}

1 个答案:

答案 0 :(得分:1)

将Observable转换为Pormise:

private letsSee(): Promise<any> {
  return this.someService.someValue.toPromise();
}