When you start the application, the getBanners()
function of the banners.service.ts
service is executed first, and then the this.headers
of the app.service.ts
service is changed.
If I switch pages, it works normally. The error only occurs when starting the application.
I want the banners.service.ts
to execute the function only after this.headers
of the service app.service.ts
has been changed.
banners.service.ts
getBanners(){
return this._http.get(this.appService.endpoint + 'banners', { headers: this.appService.headers })
.toPromise()
.then((data) => {
data = data.json();
return data;
});
}
app.service.ts
constructor() {
this.getContentType().then(data => {
this.headers.set('Content-Type', data);
});
}
private getContentType(): Promise<any> {
return 'application/json';
}