Module not found ..Cannot resolve module 'rxjs

2020-05-09 22:47发布

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

2条回答
我只想做你的唯一
2楼-- · 2020-05-09 23:19

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

查看更多
forever°为你锁心
3楼-- · 2020-05-09 23:26

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

查看更多
登录 后发表回答