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,
In the Angular 4+
, It can be done automatically.
You can change your getPriceTags
method:
export class PriceTagService {
constructor(private http: HttpClient) {}
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});
}
}
And your DataSource
class can be:
export class PriceTagDataSource extends DataSource {
constructor (private priceTagService: PriceTagService) {
super();
}
connect(): Observable {
// Here you can retrieve the Observable from service and return directly
return this.priceTagService.getPriceTags();
}
disconnect() {}
}