src/app/hero.service.ts(2,22) 中的错误:错误 TS2305:模块"F:/angu



以下是我的角度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';

对此有什么建议吗?

我认为导入路径不正确。

尝试导入,如下所示:

import 'rxjs/add/observable/of';

import { of } from 'rxjs/observable/of';

从正确的位置导入:

import 'rxjs/add/observable/of';

相关内容

最新更新