在ngOnInit()中执行POST请求后,如何刷新HTML表



访问组件invoices.ts时,它会在后台查找一些更新,并将其应用于现有更新。否则,当用户没有现有发票时,它将执行POST请求来创建发票。然而,当用户访问组件时,在ngOnInit()中调用POST和PUT操作,在刷新页面之前,我仍然会看到一个空表。如何在不使用"window.location.reload(("的情况下自动刷新HTML表以填写新开具的发票?

invoice.component.ts

ngOnInit() {
this.auth.getProfile().subscribe((profile : any) => {
this.userName = profile.user.username;
this.email = profile.user.email;
}
this.getAndUpdateInvoices();
}

getAndUpdateInvoices() {
this.invoiceService.getInvoicesn().subscribe((data : any) => {
this.invoices= data.invoice;
this.createUpdate();
})

createUpdate() {
this.createInvoice({
client: data.Client,
***etc
})
}

createInvoice(invoice) {
this.invoiceService.newInvoice(invoice).subscribe((data: any) => {
if (!data.success) {
console.log(data.message);
} else {
console.log(data.message);
}
});
}

this.invoiceService.updateInvoice(this.invoice).subscribe((data: any) => {
if (!data.success) {
console.log(data.message);              
} else {
console.log(data.message);
}
});

}

在我的invoice.component.html:中

<tr *ngFor="let invoice of invoices"  >
<td> {{invoice.hours}} </td>

如果你需要更多信息,请告诉我

只需在此处调用用于从服务类获取所有数据的方法:

createInvoice(invoice) {
this.invoiceService.newInvoice(invoice).subscribe((data: any) => {
if (!data.success) {
console.log(data.message);
} else {
console.log(data.message);
-----HERE----
}
});
}

最新更新