I\'m new to the concepts of observables and need some help with a conversion.
I have a service which returns an Observable
from a Http request,
I guess your HTTP Response is a JSON containing a PriceTag? The issue is that you want to create a PriceTag object. You can just convert the json to a PriceTag by type casting, but then it won't be a real PriceTag object.
The way we have resolved this is:
export class Serializable {
constructor(json?: any) {
if (json) {
Object.assign(this, json);
}
}
}
And then a serializable class:
export class PriceTag extends Serializable {}
Then, your GetPriceTags function needs to be changed to:
getPriceTags(): Observable {
// 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})
.map(res => new PriceTag(res.json()));
}