Angular Tour of Heroes : problems with inMemory Web API

我怕爱的太早我们不能终老 提交于 2019-12-04 10:15:50

Here is what I had to do in order to get your code to run after pulling it from your repo.

First, downgraded to angular-in-memory-web-api@0.5.4. This means changing the version in the package.json to ^0.5.4 and running npm i.

"angular-in-memory-web-api": "^0.5.4",

I have heard here and there that some were having trouble with the 0.6.0 version of angular-in-memory-web-api, so this was the first step I tried.

According to this, angular-in-memory-web-api version 0.6.0 requires Angular "^6.0.0-rc.0" and RxJS "^6.0.0-beta.1".

So, the downgrade should get you moving forward with the tutorial. Feel free to move to the Angular and RxJS versions above when you are ready.

Then, I needed to make these changes in the hero.service.ts.

Added this import:

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

Change this:

getHero(id: number): Observable<Hero> {
    return Observable.of({id: 1, name: 'test'});
}

to this:

getHero(id: number): Observable<Hero> {
    return of({id: 1, name: 'test'});
}

All was working after this. Hope this helps you out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!