小编Dev*_*Tin的帖子

如何总结角度总计?

我想用角度对表的列求和,但它不起作用:例如,如果我想对2000and 求和30004000它给了我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

0
推荐指数
1
解决办法
60
查看次数

标签 统计

angular ×1