【发布时间】:2023-02-17 02:49:45
【问题描述】:
我想制作一个仅在前一个请求返回 StatusCode 200 时发出另一个请求的方法。我使用的是 angular 15。
我的home.component.ts 看起来像这样,我想todasGuias() 一次只发出另一个请求。
todasGuias() {
this.page= 1;
while (this.page <= this.listaGuias.TotalPages) {
this.homeService.getGuias( this.year, this.month, this.glosadas, this.page)
.subscribe((data)=>{
this.listaGuias = data.Dados[0]
console.log(this.listaGuias.ResultList);
})
this.page++;
}
}
我的home.service.ts 看起来像这样:
public getGuias( year: any, month: any, glosadas: any, page:any): Observable<any> {
const token = this.token.retornaToken();
const headers = new HttpHeaders({ Authorization: `Bearer ${token}` });
return this.http.get(API/list?TpoRelatorio=1
&SomenteGlosadas=${glosadas}
&Ano=${year}
&Mes=${month}
&Page=${page}
&Count=0`,{ headers }
)
}
有帮助吗?
【问题讨论】:
标签: angular httprequest http-status-codes angular15