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

喜欢而已 提交于 2019-12-09 03:58:43

问题


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

Module rxjs not found see this

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

what should i do ?

// 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) {}
 .......
    }

回答1:


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

new Observable().toPromise();

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

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




回答2:


From rxjs 6 onwards toPromise is not an operator, it is part of observable object, you should be able to access directly without any imports



来源:https://stackoverflow.com/questions/50896544/module-not-found-cannot-resolve-module-rxjs-operators-topromise-with-angular6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!