1、示例代码:
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
blogs = [];
constructor(private httpClient: HttpClient) {
}
async ngOnInit() {
console.log('reload data before:' + this.blogs.length);
await this.reloadData();
console.log('reload data after:' + this.blogs.length);
}
async reloadData() {
let params = new HttpParams().set('typeId', 'all');
let response: any = await this.httpClient.post('http://localhost:8080/blog/getList', params).toPromise();
this.blogs = response.data;
}
}
2、控制台打印信息:
reload data before:0
reload data after:6