Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple collections in Angular-in-memory-web-api

How do we create multiple collections using Angular-in-memory-web-api? Not an issue with single collection. But I'm not able to implement it for multiple collections.

For example, I want to create say two collections in the memory db - Country and Cities. Any idea, how to do that?

like image 270
Sparrow Avatar asked Oct 20 '16 06:10

Sparrow


1 Answers

Just return it an object with both arrays. In the example from Angular, you see something like

createDb() {   let heroes = [ .. ]   return { heroes } } 

If you don't already know this, { heroes } is just shorthand for writing { heroes: heroes }. So if you have two collections, then just add it as a another property

createDb() {   let heroes = [ .. ];   let crises = [ .. ];   return { heroes, crises };   // or { heroes: heroes, crises: crises } } 

The name of the property returned will be used for the path in the URL. So you can use

/api/heroes/1 /api/crises/1 
like image 193
Paul Samsotha Avatar answered Sep 20 '22 16:09

Paul Samsotha