This is my get method.
get(url: string, options?: RequestOptionsArgs): Promise<Observable<{}>> {
return new Promise((resolve, reject) => {
this._frotzOptions(url, options).then((data) => {
if (data) {
resolve(this.http.get(url, data));
} else
resolve(false);
}).catch((err) => {
reject(err);
});
});
}
_frotzOptions method.
private _frotzOptions(urlo: string | Request, options: RequestOptionsArgs): Promise<{}> {
if (!options) {
options = {}
}
if (!options.headers) {
options.headers = new Headers();
}
return new Promise((resolve, reject) => {
this.storage.get('token').then(token => {
options.headers.append('Content-Type', 'application/json');
options.headers.append('Authorization', 'Bearer ' + token);
if (token) {
resolve(options);
}
else
resolve(false);
}).catch((err) => {
reject(err);
});
});
}
home.ts
var subscription = Observable.fromPromise(this.ahttp.get(url));
subscription.subscribe((data) => {
data.subscribe(rsp => {
console.log("rsp", rsp);
})
}, (err) => {
console.log(err)
});
When I need to use data which are resolving fro the get method, I have to use a subscribe within a subscribe! What is the best way to do this by using a subscribe! Any suggestions! Thank you!