angular - 发布新数据后,是否可以从 web api 角度获取当前 id 的值?
问题描述
我正在生成一张包含许多销售交易的发票。最初选择状态为假且有许多交易的客户并生成发票。现在,在生成发票时,我希望这些状态为真,并且所有选定的交易都分配给新生成的发票。
我能够根据所选交易生成发票。但现在我无法将该发票 ID 分配给这些交易。
如果我能得到当前生成的发票 ID,那将很容易。谁能帮我?
ngOnInit() {
this.id = this.route.snapshot.paramMap.get('id');
this.service.getSalesTransaction(this.id).subscribe((singleData: any) => {
this.service.getAllSalesTransactions().subscribe((data: any) => {
data.forEach(element => {
if (singleData.CustomerName === element.CustomerName
&& element.Status === false) {
//Pushing valid object into an array
this.salesTransaction.push(element);
//Calculating Sub Total
this.subTotal = this.salesTransaction.reduce((acc, val) => acc+=val.Total, 0);
console.log(this.subTotal);
//Calculating Tax based on the amount
if (this.subTotal <= 500) {
this.tax = (10 / 100) * this.subTotal;
console.log(this.tax);
} else {
this.tax = (5 / 100) * this.subTotal;
console.log(this.tax);
}
}
});
//Preparing data for invoice database
this.invoiceData.Tax = Math.round(this.tax);
//Creating new Invoice
this.serviceInvoice.createInvoice(this.invoiceData).subscribe((dataInvoice) => {
console.log('Invoice -', dataInvoice);
console.log(this.invoiceData);
});
});
});
});
}
解决方案
这是因为这个服务调用的行为是异步的,有时如果你使用同步的方式,会解决这个问题
推荐阅读
- python - 如何将 xlsb 文件添加到 Kedro 的目录中?
- asp.net-core-webapi - 通用记录器中的 Serilog 缺少异常
- django - 我如何根据方法订购商品
- git - 在 rebase 期间中止 git commit - 分阶段的更改丢失
- php - PHP zeropad (sprintf) AND number_format 总计
- c# - NullReferenceException:调用 transform.localScale 时未将对象引用设置为对象的实例
- reactjs - 如何在反应中为输入标签编写验证?
- python - S3 单元测试 boto 客户端
- javascript - 使用 ReactJS 自定义分页
- python - 输入二维字符串并打印