// An highlighted block
export class AppComponent {
constructor(private http: HttpClient) {
this.test().then(arr => {
// alert(arr.length === 3);
});
}
async getDemoData(): Promise<any> {
const obj = this.http.get('https://reqres.in/api/users?page=1').toPromise();
return obj;
}
async test(): Promise<any> {
const d1 = await this.getDemoData();
const d2 = await this.getDemoData();
const d3 = await this.getDemoData();
const arr = [d1, d2, d3];
console.log(arr);
return Promise.all(arr);
}
}
angular 一次方法调用中使用多个http请求的返回值 方法一
最新推荐文章于 2024-01-12 15:28:36 发布