Angular 2:url 'api/heroes' 在哪里定义?

aja*_*hiz 5 angular2-routing angular

我正在阅读Angular 2 Tour of Heroes教程的第 7 部分。在包含 InMemoryWebApiModule 之后hero.service.ts使用private heroesUrl = 'api/heroes';.

应用程序如何知道 WebAPI url 是api/heroes?我在app-routing.module.ts. 映射到 InMemoryWebApiModule 的 url 是如何工作的?

Deb*_*ahK 6

我在这里继续我的经验......对 InMemoryWebApiModule 没有深入的了解......

看来“api”是由 InMemoryWebApi 捕获的。而“英雄”是 createDb() 方法中定义的数据结构。

例如,我的看起来像这样:

private baseUrl = 'api/products';
Run Code Online (Sandbox Code Playgroud)

我的数据文件如下所示:

export class ProductData implements InMemoryDbService, InMemoryBackendConfig {
    createDb() {
        let products: IProduct[] = [ ...];
        return { products };
    }
}
Run Code Online (Sandbox Code Playgroud)