下面是我的角度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';对此有什么建议吗?
发布于 2018-05-23 07:14:24
我认为导入路径是不正确的。
试着进口如下所示:
import 'rxjs/add/observable/of';或
import { of } from 'rxjs/observable/of';发布于 2018-05-23 07:12:19
从正确的地方进口:
import 'rxjs/add/observable/of';https://stackoverflow.com/questions/50481861
复制相似问题