How to sum up the values entered in the mat-table column using mat-input in angular2

后端 未结 2 1962
臣服心动
臣服心动 2021-01-18 10:17

I am trying to sum up the values entered in the mat-table column using an input.

I have created a table with 3 columns: Account Id, A

2条回答
  •  无人共我
    2021-01-18 10:37

    try this

    In component

     ngOnInit(){
      this.accdetailservice.accountdetails()
      .subscribe(data =>
      this.dataSource1.data= data.map(obj => ({...obj, value: 0}))
      );
     }
    
    
    calculation(){ 
    return dataSource1.data.reduce((summ, v) => summ += parseInt(v.value), 0) 
    }
    

    in Html

     Total: {{calculation()}}
    

    also change to

    Edit:

    as per the chat discussion you need to use value parameter as a dynamic parameter to calculate

    So try this below way

    
        Value 
       
         
           
         
       
        
    

提交回复
热议问题