I have a service that calls the API like this:
return this._http
.post(appSettings.apiUrl + 'SomeController/SomeAction', params, {withCredentials: true, headers: this.headers})
.timeoutWith(appSettings.maxTimeHttpCalls, Observable.defer(() => Observable.throw(this._feedbackService.timeout())))
.map((response: Response) => response.json().data);
Now I want to implement a filter function on that call using rxjs/add/operator/filter
, but I can't get it to work properly.
This is the approach I have taken:
return this._http
.post(appSettings.apiUrl + 'SomeController/SomeAction', params, {withCredentials: true, headers: this.headers})
.timeoutWith(appSettings.maxTimeHttpCalls, Observable.defer(() => Observable.throw(this._feedbackService.timeout())))
.filter(response => response.json().data.Type === 5)
.map((response: Response) => response.json().data);
But no matter what I filter on, the ngFor
loop produces nothing as long as the filter is in there. If I remove it, everything works as expected.
Am I supposed to add the filter before or after the map
?
Can I filter on the response JSON like that, or do I need to use another syntax?
Example JSON
Here's an example of what the response JSON looks like:
data: [
{
"Type": 5,
"Description": "Testing",
"ID": "001525"
}
]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…