在我的应用程序中,如果数据是未定义的或来自服务的null,我的html将无法加载,并且会出现“数据未定义”错误,因此我想使用lodash,但不知道如何使用它。
在我下面的ts文件中
this._PartService.GetDataValues().subscribe(
result => {
this.distributionData = this._PartService.part_data.partMasterDataCompleteList[0].partMasterData.plantSupplies.plantSupply
}
Run Code Online (Sandbox Code Playgroud)
如果数据不存在,我将获得“ partMasterDataCompleteList”为undefiend或null,所以我在尝试使用Lodash,但我不知道如何使用它
我试图通过单击 for 循环中该行中的按钮来删除特定行,但它会删除该表的所有行。
这是我的 HTML 代码:
<table id="mytable" class="table table-bordred table-striped">
<tbody id="del">
<tr *ngFor="let cart of modalData">
<td>
<div style="display:inline-flex;">
<div style="margin-left:10px;">
<p class="font_weight" style="font-size:13px;">{{cart.ExamName}}</p>
<p>{{cart.Categoryname}}|{{cart.CompanyName}}</p>
</div>
</div>
</td>
<td>
<div style="margin-top: 32px;">
<p class="font_weight" style="font-size:13px;"></p> <span class="font_weight" style="font-size: 13px;"> {{cart.Amount| currency :'USD':'true'}} </span> </div>
</td>
<td>
<div style="margin-top: 19px;">
<button class="button_transparent" (click)="Delete(cart)"> delete </button>
</div>
</td>
</tr>
<tr> </tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
这是我的组件:
public loadData() {
let transaction = new TransactionalInformation();
this.myCartService.GetExamOrderForCart()
.subscribe(response => this.getDataOnSuccess(response),
response => this.getDataOnError(response));
} …Run Code Online (Sandbox Code Playgroud)