angular promise resolve example
Example 1: use promise in angular 8
private fetchData(){
const promise = this.httpClient.get(this.apiUrl).toPromise();
console.log(promise);
promise.then((data)=>{
console.log("Promise resolved with: " + JSON.stringify(data));
}, (error)=>{
console.log("Promise rejected with " + JSON.stringify(error));
})
}
Example 2: immediate promise resolve
Promise.resolve().then(() => {
console.log('resolved');
});
console.log('end');
// end
// resolve