How to create total price while using Array? (SOLVED)

Hi All.

First of all, you can check my codepen here :

I want to create TOTAL PRICE which is total/ summary price of all food in the list. When User click delete button on each item, it also will change the TOTAL PRICE.

Anyone can help/give advice? it would be greatly appreciated.


add a function, that calculates the totalprice

Keep in mind you have to format the output data like you want --> calculation only works with numbers.
If i need to format money and different currencies i am using

So i only format the output values and can work with numbers in my controller.

1 Like

Great Thanks, @bengtler!
It works with my app.

Hi @bengtler, in this case,
what if i want 2 digits after decimal place?
i.e : I want it display $10.00 instead of $10.

is it possible? Could you give the advice?
Code :

Thanks :smiley:

like i said… use thirdparty lib accounting.js
or write an own formatter.

ugly and fast solution use toFixed-method

1 Like

Alright @bengtler.
Many thanks for your kind help!

Hi @bengtler.
I have another case in same topic : calculating price in Ionic.

You can take a look at this codepen :

There is initial price worth: $10.00 in the total price.
When user click on (+) button to add item, i.e : LAKSA (price $4.5), the price will be updated to : $14.50 (and the button will be change to (-) minus with red background).
and then When user add BURGER (price $2.5), the price will be updated to : $17.00.

then, when user click on the LAKSA again, the price will be decrease to $12.5.
and so on … that’s happen with the all item.

I’ve found another code here :
which is looks like my case. But i get stuck on how to implement this with my case.

Do you have any clue/advice, @bengtler?

you have your ondelete function --> if clicked and our item is not added --> add the price you want, if it is added --> subtract the base price.

Store the baseprice of the product in a special key on the item.object.

1 Like

Thanks @bengtler!
for anyone who has the same case, here i share the code snippet :

$scope.onClickAdd = function(item){
    if (!item.added)
    item.added = !item.added;