1
JSON 개체의 배열이있어서 각 JSON 개체의 API 히트 결과를 각 JSON 개체의 특정 요소에 추가해야하며 최종 결과는 HTML 파일에 표시되어야합니까? 그러나 HTML 페이지는 이미 API에서 검색 한 데이터보다 먼저 렌더링됩니까?API에 대한 비동기 호출을 처리하는 방법은 무엇입니까?
<tr *ngFor="let order of Orders">
<td><img src="images/honey.jpg" style="width:50px;"/>
<span style="margin-left:10px;">{{order.productName}} <strong>[ package:</strong> {{order.packageName}}<strong>]</strong></span></td>
<td><input type="number" class="form-control" step="1" style="width:80px;" [value]="order.quantity" /></td>
<td><span>NPR Rs.{{order.Rate|number}}</span></td>
<td><strong>{{order.totalPrice}}</strong></td>
<td>
<a href="#" style="color:#F00"><i class="fa fa-trash" (click)="removeItem(order)"></i> Remove</a>
</td>
</tr>
만 totalPrice이 API 측에서 calcuating되고, 다른 모든 내용이 주문 변수로 이미 :
문제는이 같은 것입니다. TS 파일에서
:
calculatePrice(){
let i;
for(i =0;i<this.Orders.length; i++){
this.dataService.post("order/prices",this.Orders[i])
.subscribe(res=>{
this.Orders[i]['totalPrice'] = res.totalPrice;
})
}
}