angularjs - angular js checkbox and select dynamic binding to give total price -
i have working code gives sum of total item in json file after ticking 1 or of checkboxes
here controller
$scope.testfood = [{ name: item1, price: 400 }, { name: item2, price: 800 }, { name: item3, price: 1000 }]; $scope.selecteditems = []; $scope.value = function (isselected, item) { if (isselected == true) { $scope.selecteditems.push(item); } else { // console.log(item.name); angular.foreach($scope.selecteditems, function (itemrmv, $index) { if (itemrmv.itemid == item.itemid) { $scope.selecteditems.splice($index, 1); } }) } console.log($scope.selecteditems); }
the filter:
.filter('getprice', function () { return function (value, property) { var total = 0; angular.foreach(value, function (val, index) { total = total + number(val.price) }); return total.tofixed(2); } });
the html template:
<ul class="list" ng-repeat ="item in testfood"> <li class="item item-checkbox"> <label class="checkbox"> <input type="checkbox" ng-model="item.isselected" ng-change="value(item.isselected,item)"> </label> {{item.package_name}} <p>n {{item.price}}</p> </li> x <label class="item item-input"> <input type="number" value="0" min="0" step="1"> </label> </ul>
calling {{selecteditems | getprice}}
gives total price. want quantity each product calculated along side total price, how do that?
thanks.
Comments
Post a Comment