Would like to implement a generic HTTP GET service, and I have achieved it using the code snippet below:
public get(module: String): Promise<any> {
return this.http.get(module)
.toPromise()
.then(response => response.json().data as Any[])
.catch(this.handleError);}
However, I am facing an issue where I want to execute a command once the HTTP GET request is completed, but I am unsure how to accomplish this.
Adding something to the .then
step does not yield the desired result:
.then(response => response.json().data as Any[] && alert("HI"))
Alternatively, adding another .then
after the initial one causes the command to fire before the HTTP request is fully processed.
What would be the best approach to achieve this?
When utilizing the dfsq code, I am able to successfully trigger alert("HI")
, however, the response returned is undefined. Here is an example of how I am using it:
this.dataService.get("myurl").then(response => console.log(response));
Unfortunately, the output is undefined.