【发布时间】:2018-05-06 05:07:04
【问题描述】:
我在关注this tutorial(Angular2官方“快速入门”教程)
最后,有几个 http 请求(GET、POST、PUT、DELETE...),它们不是调用真实服务器,而是使用app.module.ts 中的以下行进行模拟:
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests
// and returns simulated server responses.
// Remove it when a real server is ready to receive requests.
HttpClientInMemoryWebApiModule.forRoot(
InMemoryDataService, { dataEncapsulation: false }
)
以下是应用程序发出的 HTTP 请求示例:
private heroesUrl = 'api/heroes'; // URL to web api
/** GET heroes from the server */
getHeroes (): Observable<Hero[]> {
return this.http.get<Hero[]>(this.heroesUrl)
.pipe(
tap(heroes => this.log(`fetched heroes`)),
catchError(this.handleError('getHeroes', []))
);
}
问题:有没有办法配置这个 InMemoryDataService 所期望的端点?因此,例如,我可以将 Url 更改为 api/heroes/getAll。
【问题讨论】:
-
我认为 this 是你要找的。span>
标签: angular http local-storage angular2-services endpoint