I am new to observable concepts and need help transforming.
I have a service that returns an Observable<Response> from an Http request, but I need to convert it to an Observable<PriceTag> in order to use it in a DataSource inside the connect method.
Is there any way to do this?
This is the method from my service:
getPriceTags(): Observable<Response> { // Set the request headers const headers = new Headers({ 'Content-Type': 'application/json' }); // Returns the request observable return this.http.post(Constants.WEBSERVICE_ADDRESS + "/priceTag", null, {headers: headers}); }
And here is the DataSource class, where I need to return it as an Observable<PriceTag> :
export class PriceTagDataSource extends DataSource<PriceTag> { constructor (private priceTagService: PriceTagService) { super(); } connect(): Observable<PriceTag> {
Here is an example response from my request:
{ // This object is used to check if the query on the server was sucessful "query": { "sucessful": true }, // These are my PriceTags "tags": [ { "id": "1", "name": "MAIN" }, { "id": "2", "name": "CARD" } ] }
source share