我想用角度对表的列求和,但它不起作用:例如,如果我想对2000and 求和3000,4000它给了我200030004000,但我想对它求和就意味着9000它是串联的。
client.component.ts
clients: Client[];
total: number=0;
constructor(private clientService:ClientService) { }
ngOnInit() {
this.clientService.getClients().subscribe(clients => {
this.clients=clients;
this.total = this.getTotal();
});
}
getTotal() {
return this.clients.reduce((total, client) => {
return total + client.balance;
}, 0)
}
Run Code Online (Sandbox Code Playgroud)
client.component.html
<div class="col-md-6">
<h4 class="text-right">Total : {{ total | currency:"USD": "symbol" }}</h4>
</div>
Run Code Online (Sandbox Code Playgroud) angular ×1