英雄角度游:inMemory Web API问题 [英] Angular Tour of Heroes : problems with inMemory Web API
问题描述
我正在关注著名的Angular教程,《英雄之旅》,但我却步履蹒跚.
I'm following the famous Angular tutorial, Tour of Heroes, but I'm struggling with one step.
在第六课程HTTP 上,我们使用了一种用于模拟API调用的工具到API.
On the sixth course, HTTP, we are using a tool made to mimick API calls to an API.
我想我遵循了所有步骤,直到这点表示愚弄的地方:
I think I followed all the steps, up to this point where it is stated the folliwing :
刷新浏览器. Hero数据应该可以从模拟服务器成功加载.
Refresh the browser. The hero data should successfully load from the mock server.
但是我可能错过了一些东西:http调用都给出了http 500标头,错误为Object(...) is not a function
.
But I may have missed something : the http calls all give http 500 headers with the error being Object(...) is not a function
.
我是否错过了有关创建路线的事情?在我看来,inMemory wep API似乎不需要路由.
Have I missed something about creating a route ? It seems odd to me that inMemory wep API does not seem to need a route.
我的测试代码在这里: https://github.com/MarcBrillault/tourOfHeroes/tree/StackOverflow
My test code is available here : https://github.com/MarcBrillault/tourOfHeroes/tree/StackOverflow
推荐答案
这是我要做的,以便在从存储库中提取代码后才能运行您的代码.
Here is what I had to do in order to get your code to run after pulling it from your repo.
首先,降级为angular-in-memory-web-api@0.5.4
.这意味着将 package.json 中的版本更改为^0.5.4
并运行npm i
.
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",
我在这里和那里都听说过,有些人在使用angular-in-memory-web-api
的0.6.0版本遇到了麻烦,所以这是我尝试的第一步.
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.
根据此,angular-in-memory-web-api
版本0.6.0需要 Angular"^ 6.0.0-rc.0"和RxJS"^ 6.0.0-beta.1" .
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".
因此,降级可以使您继续学习本教程.准备就绪后,随时可以移至上面的Angular和RxJS版本.
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.
然后,我需要在 hero.service.ts 中进行这些更改.
Then, I needed to make these changes in the hero.service.ts.
添加了此导入:
import { of } from 'rxjs/observable/of';
更改此:
getHero(id: number): Observable<Hero> {
return Observable.of({id: 1, name: 'test'});
}
对此:
getHero(id: number): Observable<Hero> {
return of({id: 1, name: 'test'});
}
此后所有人都在工作.希望这对您有所帮助.
All was working after this. Hope this helps you out.
这篇关于英雄角度游:inMemory Web API问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!