set the ngModel value as the input's value

Viewed 707

I am trying to call the function inside [(ngModel)] but it give me error Unexpected token '=' at column 27 in [sum(data,'feeAssign') || 0=$event]

json data

 { "org_Id": 1, "academic_Id": 1, "fee_Category_Id": 5, "type_Id": 12, "duration_Id": 2, "structure_Id": 59, "sub_structure_Id": 18, "installment_Id": 1, "type_Det_Name": "Term Fees - Term", "student_Id": 0, "receipt_Id": 0, "receipt_Code": 0, "structure_Amount": 4, "discountAmount": 0, "receipt_Amount": 0, "responseCode": 0, "responseMessage": "Fee Collection Received Succesfully", "feeAssign": 4, "paid": 0, "feeBalance": 4, "payable": 4 }

html component code

 <nz-input-number [nzDisabled]="true" [(ngModel)]="sum(data,'feeAssign') || 0"  [nzMin]="1" 
[nzStep]="1">
 </nz-input-number>

.ts file code

 sum(array, key) { 
return array.reduce(function (sum, current) {
  debugger;
    return sum + current[key];
}, 0);
}

I tried with [ngModel] there is no error but it is not calling the sum function in that case.

I want to call the function which sum the value in array and returned the updated values.

1 Answers

You can use only [ngModel]: [ngModel]="sum(data,'feeAssign') || 0"

one-way binding to ngModel with [] syntax

Related