打字稿代码:
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import { Hero } from './hero';
import { HEROES } from './mock-heroes';
@Injectable({
providedIn: 'root'
})
export class HeroService {
constructor() { }
getHeroes(): Observable<Hero[]> {
return of(HEROES);
}
}
错误信息:
错误TS2307:找不到模块“ rxjs-compat / Observable”。node_modules / rxjs / observable / of.d.ts(1,15):错误TS2307:找不到模块“ rxjs-compat / observable / of”。src / app / hero.service.ts(2,10):错误TS2305:模块'“ F:/ heroes / node_modules / rxjs / Observable” /没有可导出成员。src / app / hero.service.ts(15,12):错误TS2304:找不到名称“ of”。
package.json
Angular版本的文件: