Angular Tour of Heroes:inMemory Web API 的问题 [英] Angular Tour of Heroes : problems with inMemory Web API

查看:15
本文介绍了Angular Tour of Heroes: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 :

刷新浏览器.英雄数据应该成功从模拟服务器加载.

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/树/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.

这篇关于Angular Tour of Heroes:inMemory Web API 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆