我正在添加一些值。但是,当我对其进行过滤时,值不会改变。当任何人选择仅显示那个policy_id的总和的策略时,我需要更改总和。
getClaims(){
if(this.userFilter.company_id){
this.url = 'http://api.igiinsurance.com.pk:8888/insurance_IGItakaful/insurance-api/get_claims.php?offset=0&limit=1000&company_id='+this.userFilter.company_id;
this.spinner.show();
}
else{
this.url = 'http://api.igiinsurance.com.pk:8888/insurance_IGItakaful/insurance-api/get_claims.php?offset=0&limit=50';
this.spinner.show();
}
this.clientData = this.httpClient.get<any>(this.url).
subscribe(data => {
console.log(data);
this.spinner.hide();
this.data = data.records;
this.data.forEach(d => this.policy_id.add(d.policy_id));
var status = 'settled';
var status2 = 'submitted';
var countsettled = this.data.filter((obj) => obj.status === status).length;
var countunsettled = this.data.filter((obj) => obj.status === status2).length;
console.log(countsettled);
this.countsettled = countsettled;
console.log(countunsettled);
this.countunsettled = countunsettled;
const sum1 = this.data.filter(item => item.status === 'settled')
.reduce((acc, item) => acc + Number(item.approved_value), 0);
console.log(sum1);
this.sum1 = sum1;
const sum2 = this.data.filter(item => item.status === 'submitted')
.reduce((acc, item) => acc + Number(item.approved_value), 0);
console.log(sum2);
this.sum2 = sum2;
});
}
}
.html
<div class="col-md-3">
<div class="form-group">
<label for="">Policy</label>
<select class="form-control" [(ngModel)]="userFilter.policy_id" >
<option *ngFor="let policy of policy_id" value="{{policy}}">{{policy}}</option>
</select>
</div>
</div>
如果用户选择“策略”,我需要对值求和。有人可以帮忙吗,谢谢