angular promise all code example
Example 1: promise all
Promise.all([Promise1, Promise2, Promise3])
.then(result) => {
console.log(result)
})
.catch(error => console.log(`Error in promises ${error}`))
Example 2: Promise.all
const promise1 = Promise.resolve(3);
const promise2 = 42;
const promise3 = new Promise(function(resolve, reject) {
setTimeout(resolve, 100, 'foo');
});
Promise.all([promise1, promise2, promise3]).then(function(values) {
console.log(values);
});
Example 3: 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 4: use promise in angular 8
private fetchData(){
const promise = this.httpClient.get(this.apiUrl).toPromise();
console.log(promise);
}