无法解决Angular 6中的依赖关系

时间:2018-06-13 07:14:28

标签: angular angular6

我正在尝试构建一个小型的Mean-Stack CRUD应用程序。我使用的是最新的CLI和Angular 6

为此,我创建了一个导入模型的服务文件,到目前为止没什么了不起的......

但是当它现在尝试编译时,它给了我:

ERROR in ./src/app/common/share.service.ts
Module not found: Error: Can't resolve 'rxjs/add/operator/map' in 'C:\Users\Thorben\Desktop\FrameworksExam\Tut\client\src\app\common'
ERROR in ./src/app/common/share.service.ts
Module not found: Error: Can't resolve 'rxjs/add/operator/toPromise' in 'C:\Users\Thorben\Desktop\FrameworksExam\Tut\client\src\app\common'
i 「wdm」: Failed to compile.
ERROR in node_modules/rxjs/Observable.d.ts(1,15): error TS2307: Cannot find module 'rxjs-compat/Observable'.
src/app/common/share.service.ts(3,10): error TS2305: Module '"C:/Users/Thorben/Desktop/FrameworksExam/Tut/client/node_modules/rxjs/Observable"' has no exported member 'Ob
servable'.

我的文件如下:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

import { Share } from './share.model';

@Injectable()
export class ShareService {
  selectedShare: Share;
  shares: Share[];
  readonly baseURL = 'http://localhost:3000/shares';

  constructor(private http: HttpClient) { }

  createShare(share: Share) {
    return this.http.post(this.baseURL, share);
  }

  getShareList() {
    return this.http.get(this.baseURL);
  }

  updateShare(share: Share) {
    return this.http.put(this.baseURL + `/${share._id}`, share);
  }

  deleteShare(_id: string) {
    return this.http.delete(this.baseURL + `/${_id}`);
  }

}

我注意错了或者问题是什么问题:(

1 个答案:

答案 0 :(得分:0)

在Angular 6.0中,导入语法有所不同。您可以看到here