以下是我的角度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);
}
}
错误:
ERROR in src/app/hero.service.ts(2,22): error TS2305: Module '"F:/practice/Angular/cli/angular-tour-of-heroes/node_modules/rxjs/Rx"' has no exported member 'of'.
以下是我试过的一些没有正面结果的事情:
import { Observable, of } from 'rxjs';
和
import { Observable, of } from 'rxjs/Observable';
对此有何建议?
答案 0 :(得分:0)
从正确的地方导入:
import 'rxjs/add/observable/of';
答案 1 :(得分:0)
我认为导入路径不正确。
尝试导入如下:
import 'rxjs/add/observable/of';
OR
import { of } from 'rxjs/observable/of';