Reputation: 799
I have a service which extends another service. I'd like to override the all
method to behave differently in this service.
The problem I'm having is I'd like to manipulate the data I get and I only want the data
value in the array I'll return.
export class ChildService extends ParentService {
constructor(http: HttpClient) {
super(http, myService);
}
all(arg1, arg2) {
return super.all(limit, filter).pipe(
flatMap((data) => {
console.log(data);
// [{data: [1, 2, 3]}, {data: [4, 5, 6]}]
// expected: [1, 2, 3, 4, 5, 6]
return of();
})
);
}
}
Upvotes: 0
Views: 367
Reputation: 8022
Looks like you want array's flatMap method rather than RxJS's flatMap operator
(which is an alias of RxJS's mergeMap operator).
Maybe something like this?
all(arg1, arg2) {
return super.all(arg1, arg2).pipe(
map(data => data.flatMap(v => v.data))
);
}
Upvotes: 1