如何"赶上"所有更改过的对象并为每个对象调用api?

时间:2017-09-08 07:33:05

标签: angular

  <div class="ui-g" *ngFor="let product of products;let i=index" (change)="sum(i)" (click)="selectItemForDelete(product)">
    <input  class="ui-g-6" type="text" [(ngModel)]="product.productName" disabled>
     <div class="ui-g-6 center">
          <input class="ui-g-2" [(ngModel)]="product.quantity">
          <input class="ui-g-4 right"  [ngModel]="product.itemamount | toNumber | number:'1.2-2'" (ngModelChange)="product.itemamount = $event">
          <input class="ui-g-2 right"  [ngModel]="product.discountamount | toNumber | number:'1.2-2'" (ngModelChange)="product.discountamount = $event">
          <input class="ui-g-4 right" [ngModel]="product.unitprice | toNumber | number:'1.2-2'" (ngModelChange)="product.unitprice = $event">
     </div>

我有api只能收到一件物品。所以我想要的是&#34;赶上&#34;所有更改的对象并为每个对象调用api。任何建议我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

好吧,如果您不介意进行多次http调用,您可以做的是实现OnChanges:

export class MyClass implements OnInit, OnChanges {
    constructor() {}
    ngOnInit() {}
    ngOnChanges() {
        // Each time your model changes, this function is called
        // Make your http calls here. 
        // You can use Observable.debounceTime() to delay calls 
    }
}