You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
Currently following forms of HTTP GET Requests are supported:
GET api/heroes/42 // the character with id=42
GET api/heroes?name=^j // 'j' is a regex; returns heroes whose name starting with 'j' or 'J'
To mock a Search Component, it would be preferable to find across any fields, in a given Collection. Something like:
GET api/heroes?search=^j // 'j' is a regex; returns heroes seen in **any** of the fields starting with 'j' or 'J'
A solution might be to provide a function that takes a collection input, an [ optional ] searchKey and returns a modified collection that contains an additional array property searchKey . This searchKey array property will contain all keywords pertinent to that record :
// functionsearchAnything(collection: heroes[],searchKey="search"){returnheroes.map(hero=>{hero[searchKey]=// parse keywords from *hero* recordreturnhero;});}
For example to make Heroes search anything, usage would look like :
import{InMemoryDbService}from'angular-in-memory-web-api';exportclassInMemHeroServiceimplementsInMemoryDbService{createDb(){letheroes=[{id: '1',name: 'Batman',movies: ['The Dark Knight']},{id: '2',name: 'Bond',movies: ['Casino Royale']}];letvillians=[{id: '1',name: 'Joker',movie: ['The Dark Knight']}];return{searchAnything(heroes), villians };}}