I have an array of objects called members
members = [
{id:'1', firstName:'John', lastName:'Black', birthDate:'1956-11-22', gender:'Male', email:'johnblack@gmail.com', phone:'806-555-1234'}
{id:'2', firstName:'Josh', lastName:'Black', birthDate:'1950-02-21', gender:'Male', email:'joshblack@gmail.com', phone:'806-555-1234'}
{id:'3', firstName:'Johny', lastName:'Black', birthDate:'1953-02-03', gender:'Male', email:'johnyblack@gmail.com', phone:'806-555-1234'}
]
I need to get objects from this array based on birthDate using HTTP request of angular-in-memory-web-api, like: greater than / less than any given date.
So, what can be the conditional params for getting a date greater than any given date?
url: api/members/?birthDate{condition}{givenDate}
In short - you can't. At least till version of current writing (0.6.0)
You can try to use regex expressions but regex doesn't do well with value comparisons (especially for date formats). And why bother? You will be using angular-in-memory-web-api only on mock up, so just filter the returned data set in the service like this:
getMembers(value?: string): Observable<Member[]> {
return this.http.get("api/members")
.map((response:Response) => {
let members= <Member[]>response.json().data;
if (!value) {
return members;
}
return members.filter(v => v.birthDate<=value);
})
.do(data => console.log('members: ' + JSON.stringify(data)))
}
Note, we can compare it as string because of your YYYY-mm-dd format, otherwise value and birthDate should be type Date