I have a little problem while develop an app in ionic : calculating price while using array.
You can take a look at this codepen : http://codepen.io/harked/pen/gpvdNK
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 : [http://codepen.io/harked/pen/KpQrMW][1]
which is looks like my case. But i get stuck on how to implement this with my case.
Anyone have a clue/advice? It would be greatly appreciated.
Just bind the initial price to the $scope
directly and update the value in your onClickAdd()
function.
<div class="item item-divider">Restaurant 1<span class="item-note">$ {{initialPrice}}</span></div>
In your controller:
$scope.initialPrice = 10;
$scope.onClickAdd = function(item){
if(!item.added)
$scope.initialPrice+=item.price
else
$scope.initialPrice-=item.price
item.added = !item.added;
};
Codepen here.