I have a service that calls the API as follows:
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 for this call using rxjs/add/operator/filter , but I cannot get it to work correctly.
This is the approach I did:
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, the ngFor loop ngFor nothing while the filter is there. If I remove it, everything will work as expected.
Should I add a filter before or after map ?
Can I filter on a JSON response like this, or do I need to use a different syntax?
JSON example
Here is an example of what the JSON response looks like:
data: [ { "Type": 5, "Description": "Testing", "ID": "001525" } ]
source share