本文介绍了无法在角度网络服务中解析 toPromise的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个非常简单的角度服务:

I am trying to create a very simple angular service:

import { Http, Response } from '@angular/http';
import 'rxjs/add/operator/toPromise';

export class Webservice {

  constructor(private http: Http) {

  }

  getMessages() {
    return this.http.get('http://localhost:63962/api/someshittyendpoint').toPromise();
  }
}

无论我做什么,我都会得到以下 Module not found: Error: Can't resolve 'rxjs/add/operator/toPromise'.

Whatever I do, I get the following Module not found: Error: Can't resolve 'rxjs/add/operator/toPromise'.

我已经安装了 rxjs-compat 并验证了该模块实际上在路径上.我不明白怎么回事?

I have installed rxjs-compat and verified that the module actually is on the path. I don't understand what's wrong?

提前致谢!

推荐答案

toPromise 不是运算符.它是 Observable 类上的一个方法,这意味着您不必导入它:

toPromise is not an operator. It's a method on the Observable class which means you don't have to import it:

查看源代码:https:///github.com/ReactiveX/rxjs/blob/5.5.11/src/Observable.ts#L332-L354

这篇关于无法在角度网络服务中解析 toPromise的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 23:29