找不到模块..无法使用 Angular6 解析模块“rxjs/operators/toPromise" [英] Module not found ..Cannot resolve module 'rxjs/operators/toPromise with Angular6

查看:33
本文介绍了找不到模块..无法使用 Angular6 解析模块“rxjs/operators/toPromise"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试使用 angular 6 构建应用程序时收到错误消息,但不知道该怎么做.

I am receiving an error when trying to build my application using angular 6 and have no idea what to do.

未找到模块 rxjs看到这个

Module not found ..Cannot resolve module 'rxjs/operators/toPromise  

我该怎么办?

//contact.service.ts

// the contact.service.ts

import { Injectable } from '@angular/core';
    import { Contact } from './contact';
    import { Http, Response } from '@angular/http';
    import 'rxjs/add/operator/toPromise';

    @Injectable()
    export class ContactService {
      private contactsUrl = '/api/contacts';
      constructor (private http: Http) {}
 .......
    }

推荐答案

尝试删除 import 语句.没有那个它应该可以工作.下面的代码有效.

try to remove the import statement. It should work without that. Below code works.

new Observable().toPromise();

从 rxjs 5.5 开始,toPromise:现在作为 Observable 的永久方法存在"

From rxjs 5.5, "toPromise: now exists as a permanent method on Observable"

https://github.com/ReactiveX/rxjs/blob/master/CHANGELOG.md

这篇关于找不到模块..无法使用 Angular6 解析模块“rxjs/operators/toPromise"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆