I was going through part 7 of Angular 2 Tour of Heroes tutorial. After including InMemoryWebApiModule the hero.service.ts
uses private heroesUrl = 'api/heroes';
.
How does the app know the WebAPI url is api/heroes
? I don't see this defined in app-routing.module.ts
. How does the url mapping to InMemoryWebApiModule work?
I'm going on my experience here ... not in depth knowledge of the InMemoryWebApiModule...
It appears that the "api" is captured by the InMemoryWebApi. And the "heroes" is the data structure defined in the createDb() method.
For example, mine looks like this:
private baseUrl = 'api/products';
And my data file looks like this:
export class ProductData implements InMemoryDbService, InMemoryBackendConfig {
createDb() {
let products: IProduct[] = [ ...];
return { products };
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With