html - Non-negitive number button in angular -
i creating counting app using ionic framework. have positive button predefined number (in services.js) , corresponding negitive number same predefined number subtract number. template code;
<a class="item list-inset item-thumbnail-left item item-button-right"> <img ng-src=" {{ menu.imgsrc1 }} "> <h2>{{ menu.fooditem1 }}</h2> <p>{{ menu.data1 }}</p> <button id="plus" class="button button-icon icon round-button" ng-click="count = count + {{ menu.calories1 }} "> {{ menu.calories1 }} </button> <button id="minus" class="button button-icon icon round-button" ng-click="count = count - {{ menu.calories1 }} "> - </button> </a>
this services code;
var menus = [ { title: 'breakfast', fooditem1: "cereal", data1: 'calories per 250g serving', imgsrc1: "img/almond.jpg", calories1: 17, fooditem2: "bread", data2: 'calories per wholegrain slice', imgsrc2: "img/almond.jpg", calories2: 25, fooditem3: "pastries", data3: 'calories per piece', imgsrc3: "img/almond.jpg", calories3: 75 }, { title: 'lunch', description: 'wrap, sandwich, soup...', fooditem1: 'wrap', data1: 'calories per wholegrain wrap', imgsrc1: "img/almond.jpg", calories1: 567, fooditem2: "sandwich", data2: 'calories per brown slice', imgsrc2: "img/almond.jpg", calories2: 567, fooditem3: "chicken soup", data3: 'calories per 250ml bowl', imgsrc3: "img/almond.jpg", calories3: 567 } ];
i not want negitive numbers go below zero. understanding need use math.floor() method counteract button entering negative zone how write without compromising exists already. need controller?
i try understand expecting : don't want number count = count - {{ menu.calories1 }}
negative ?
first, i'm never adding data manipulation html. call function of controller has data manipulation.
for instance :
<button id="minus" class="button button-icon icon round-button" ng-click="count = count - {{ menu.calories1 }} "> - </button>
will changed
<button id="minus" class="button button-icon icon round-button" ng-click="removecal(menu.calories1)"> - </button>
and creation of removecal function controller
$scope.removecal = function(val) { $scope.count -= val; }
then if want number >= 0 time add if rule manage case
$scope.removecal = function(val) { $scope.count -= val; if($scope.count <0) $scope.count = 0; }
Comments
Post a Comment