0
I created a service to run GET / POST / DELETE and PUT solitaire. When I make the first request I get Zoneawarepromise in the body of the message. How to access data within Zoneawarepromise or change my code to not return Zoneawarepromise?
Below the GET within the service
public get(url: string) {
const header = this.createHeader();
return new Promise(async(resolve) => {
try {
const result = this._HttpClient.get(url, { headers: header }).toPromise();
resolve({ success: true, data: result, error: undefined });
} catch (error) {
resolve({ success: false, data: {}, error });
}
});
}
Here’s my request inside the Component.
this._HttpService.get(`${ServerUrl.ApiUrl}MarkingGet`).then(data => console.log(data));
I don’t understand, because it involved the get in a
Promise
? Alíás should go in the documentation ofAngular
and see how does a service get and how consumes, has nothing to do with it there. Just to get an idea Angular uses Observables and for the call of the method uses subscribe.– LeAndrade
@Leandrade the idea is to create a service and decrease the amount of repeated codes. But anyway I will do a read in the documentation
– RRV