我想通过遵循教程第7步HTTP(https://angular.io/tutorial/toh-pt6)来学习Angular 2。但hero.service.ts
中的功能getHeroes()
仍然不会返回任何内容。角度教程无法接收来自http呼叫的数据
getHeroes(): Promise<Hero[]> {
return this.http.get(this.heroesUrl)
.toPromise()
.then(response => response.json().data as Hero[])
.catch(this.handleError);
}
其中模拟服务从InMemoryDbService
执行。
有什么想法吗?
是的,我做到了。该应用程序正在工作,但没有数据 – beewest
您是否已将该模块添加到'app.module.ts'中的导入依赖项? – edkeveked
我确实添加了InMemoryWebApiModule.forRoot(InMemoryDataService), – beewest