How to make a sum?

I can help make the sum of price and show in the view or give an example?

<ion-item-sliding *ngFor="let item of meVendi|async" >
      <ion-item>
        <ion-label>
          <h1>Carlos Pidio</h1>
         
            <ion-list>
              <h2>{{item.Platito.name}} &nbsp;&nbsp;${{item.Platito.price}}</h2>
              <h2>{{item.carnita.name}} &nbsp;&nbsp;${{item.carnita.price}}</h2>
              <h2>{{item.Adicionar.name}} &nbsp;&nbsp;${{item.Adicionar.price}}</h2>
            </ion-list>  
        </ion-label>
      </ion-item>
      
   
    </ion-item-sliding>

You don’t say what you want to sum over, but you can include {{functionCalls()}} in interpolation syntax as well, so you could just do the sum on demand in the controller, or have a totalPrice property that is updated with the sum as needed.

Hello I tried to do the sum and I sale NaN

export class AboutPage {
  meVendi: FirebaseListObservable<any>;

    constructor(public navCtrl: NavController,public alertCtrl:AlertController, public database:AngularFireDatabase, public event:Events ) {
    this.meVendi = this.database.list('/Evendido');

  }
  total_suma = 0;

  suma (valor){
    this.total_suma+=valor;
    
  }
  

 


}
  
<ion-content padding>
  <ion-list>
    <ion-item-sliding *ngFor="let item of meVendi|async" >
      <ion-item>
        <ion-label>
          <h1>Carlos Pidio</h1>
         
            <ion-list>
              <h2>{{item.Platito.name}} &nbsp;&nbsp;${{item.Platito.price}} {{suma(item.Platito.price)}}</h2>
              <h2>{{item.carnita.name}} &nbsp;&nbsp;${{item.carnita.price}} {{suma(item.carnita.price)}}</h2>
              <h2>{{item.Adicionar.name}} &nbsp;&nbsp;${{item.Adicionar.price}}  {{suma(item.Adicionar.price)}}</h2>
            </ion-list>  
        </ion-label>
      </ion-item>


   
    </ion-item-sliding>
          <span>total dela suma es: {{total_suma}}</span>
    

  </ion-list>

</ion-content>

I do not see how suma() is ever called.

I can not understand you, can you make me an example porfa?

suma (valor){
this.total_suma+=valor;
}

Where do you call that function? We can’t see the function call anywhere in your code. What do you want to count exactly?

1 Like

What I want to add is the value of the price and the function and here I am adding the function

<h2>{{item.Platito.name}} &nbsp;&nbsp;${{item.Platito.price}} {{suma(item.Platito.price)}}</h2>
              <h2>{{item.carnita.name}} &nbsp;&nbsp;${{item.carnita.price}} {{suma(item.carnita.price)}}</h2>
              <h2>{{item.Adicionar.name}} &nbsp;&nbsp;${{item.Adicionar.price}}  {{suma(item.Adicionar.price)}}</h2>

And where I’m adding the function<h2>{{item.Platito.name}} &nbsp;&nbsp;${{item.Platito.price}} {{suma(item.Platito.price)}}</h2>

Your function does not return a value. If you want to show the result of your method you have to return it.

  suma (valor){
    this.total_suma+=valor;
    return  this.total_suma;
  }

Your binding makes no sense without a return value.

{{suma(item.Adicionar.price)}}

I keep coming out

Any solution to this?

Please create a new thread containing code (posted as text, not images) describing:

  • what you are trying to do
  • what code you used
  • what you expected to happen
  • what actually happened

This thread should not be continued, because it is part of a deluded effort to abuse templates.