Ionic 2 SUM array from database


#1

anyone ? can you explain to me how this is working, i really bad with this logic.
number 1 and 3 data is from database
number 2 and 4 is input cliend side.

i not yet doing anything right now in script coz i dont know what i must to do first


#2

Your question is really vague, so I have no idea whether this is going to be the least bit useful, but:

total: number;
banana: number;
durian: number;

calcTotal(): void {
  Promise.all(this._storage.get('apple'), this._storage.get('cherry').then((ac) => {
    this.total = ac[0] * this.banana + ac[1] * this.durian;
  });
}

<ion-input [(ngModel)]="banana"></ion-input>
<ion-input [(ngModel)}="durian"></ion-input>
<button (click)="calcTotal()"></button>
<div>total: {{total}}</div>

#3

how can that code will be dinamy insted from database


#4

How can I possibly know how you get things from “database”? I got it from a storage provider that returns promises. You’re either going to have to adapt that to your situation or describe precisely (preferably with code) how you are getting anything from this nebulous “database”.