Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
src/app/hero.service.ts(2,22)中的错误:错误TS2305:Module'&引用;F:/angular tour of heroes/node_modules/rxjs/Rx"';没有导出的成员';属于';_Angular_Rxjs - Fatal编程技术网

src/app/hero.service.ts(2,22)中的错误:错误TS2305:Module'&引用;F:/angular tour of heroes/node_modules/rxjs/Rx"';没有导出的成员';属于';

src/app/hero.service.ts(2,22)中的错误:错误TS2305:Module'&引用;F:/angular tour of heroes/node_modules/rxjs/Rx"';没有导出的成员';属于';,angular,rxjs,Angular,Rxjs,下面是我的angularpackage.json设置 "dependencies": { "@angular/animations": "^5.2.11", "@angular/common": "^5.2.11", "@angular/compiler": "^5.2.11", "@angular/core": "^5.2.11", "@angular/forms": "^5.2.11", "@angular/http": "^5.2.11", "@angular/

下面是我的angular
package.json
设置

"dependencies": {
  "@angular/animations": "^5.2.11",
  "@angular/common": "^5.2.11",
  "@angular/compiler": "^5.2.11",
  "@angular/core": "^5.2.11",
  "@angular/forms": "^5.2.11",
  "@angular/http": "^5.2.11",
  "@angular/platform-browser": "^5.2.11",
  "@angular/platform-browser-dynamic": "^5.2.11",
  "@angular/router": "^5.2.11",
  "core-js": "^2.4.1",
  "rxjs": "^5.5.10",
  "zone.js": "^0.8.19"
},

"devDependencies": {
    "@angular/cli": "~1.7.4",
    "@angular/compiler-cli": "^5.2.11",
    "@angular/language-service": "^5.2.11"
}
下面是HeroService组件的代码,并获取下面发布的错误

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import 'rxjs/add/Observable/of';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';

@Injectable()
export class HeroService {
  constructor() { }
  getHeroes() : Observable<Hero[]> {
      return of(HEROES);
  }

}
以下是我尝试过的一些事情,但没有取得积极的结果:

import { Observable, of } from 'rxjs';


对此有何建议?

从正确的位置导入:

import 'rxjs/add/observable/of';

我认为导入路径不正确

尝试按如下方式导入:

import 'rxjs/add/observable/of';


但它仍然抛出“src/app/hero.service.ts(14,11)中的错误:错误TS2304:找不到名称'of'。”上面的答案是从'rxjs/observate/of'导入{of};这一条有效:“从'rxjs/observable/of'导入{of};”“太好了!!快乐编码:)
import 'rxjs/add/observable/of';
import 'rxjs/add/observable/of';
import { of } from 'rxjs/observable/of';