Reputation: 10844
I'm trying to use ngrx entity dataservice for the first time
The API call is being made and I'm recieving the expected data
But when ngrx tries to proccess it it gets an error on the reduce method
I have checked other similar questions:
But have not found what is causing this.
The response contains an id
and is not undefined, how can I solve this ?
Since the error is happening inside ngrx I'm not sure about what part of my code show you to help me address this.
Upvotes: 3
Views: 921
Reputation: 10844
This happens when te result contains an array of objects and another data, so the data has to be mapped - http://github.com/ngrx/platform/issues/2434#issuecomment-751560440
Upvotes: 1
Reputation: 1857
Make sure you map your response as Array. This will resolve your issue:
Example :
@Injectable()
export class ForReportsDataService extends DefaultDataService<any> {
constructor(http:HttpClient, httpUrlGenerator: HttpUrlGenerator, private dataService: DataService) {
super('forReport', http, httpUrlGenerator);
}
getAll(): Observable<any> {
return from(this.dataService.GET("/api/reports").pipe( // map here
map(res => res["items"]) // map here
));
}
}
Upvotes: 1