Property 'subscribe' does not exist on type 'Promise'
Following caffinatedmonkey's suggestion, I ended up with this working function:
getPlanograms() {
//API URL
let requestURL = 'https://myapiurlhere';
return Observable
.fromPromise(this.storage.get('id_token'))
.flatMap(token =>{
let headers = new Headers({'Content-Type': 'application/json'});
headers.append('Authorization', 'Bearer ' + token);
let options = new RequestOptions({headers: headers});
return this.http.get(requestURL, options)
.map(response => <Planogram[]>response.json())
.catch(this.handleError);
}
);
}
You could consume with .then()
by changing:
ionViewDidLoad () {
this.merchandisingDataService.getPlanograms()
.then(Planogram => this.planograms = Planogram);
}
Or, you could make getPlanograms
return an Observable
.
getPlanograms() {
// API URL
let requestURL = 'https://myapiurlhere';
let headers = new Headers({'Content-Type': 'application/json'});
// this converts from promise to observable
return Observable.fromPromise(this.storage.ready()
.then(() => this.storage.get('id_token'))
.then((val) => {
headers.append('Authorization', 'Bearer ' + this.authCredentials.token);
let options = new RequestOptions({headers: headers});
return this.http.post(requestURL, {}, options)
// map converts from observable to promise
// (returned by response.json())
.map(response => <Planogram[]>response.json());
});
}));
}
Now you can consume with .subscribe()
as you did in the question.