Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2: Where is url 'api/heroes' defined?

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?

like image 839
ajay_whiz Avatar asked Aug 16 '17 20:08

ajay_whiz


1 Answers

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 };
    }
}
like image 62
DeborahK Avatar answered Oct 02 '22 23:10

DeborahK