我们在ng-repeat中有加号和减号按钮。每个按钮应在特定文本框内增加或减少值。无论点击按钮只有一个事件正在触发,有2个递增和递减功能。虽然两个按钮都有不同的功能名称。
这是我用来触发事件的控制器代码
app.controller('MultiCheckOutCtrl',function($ionicPlatform,$ionicHistory,$rootScope,$scope,$state,$http,webservices,myconfig,$ionicPopup,$ionicLoading){
console.clear();
$rootScope.$ionicGoBack = function(backCount) {
$ionicHistory.goBack(backCount);
//alert("back button");
$( ".datepicker" ).datepicker("hide");
};
$ionicPlatform.registerBackButtonAction(function() {
$( ".datepicker" ).datepicker("hide");
$ionicHistory.goBack();
}, 100);
// increment for + button //
$ionicLoading.show({
template: "Please Wait."
});
$scope.decrement = function(){
alert("decrement");
}//end of decrement
$scope.increment = function(){
alert("increment");
}
$scope.userBookingDetails = {};
$scope.usrdata={};
$scope.errorStatus=false; webservices.getPackagesBasedOnResortId($scope.resortid).success(function(data) {
//console.log("Inside MultiCheckOutCtrl controller : "+data[0].bannerimage);
$scope.userBookingDetails = data;
//console.clear();
//console.log(data);
$ionicLoading.hide();
});
});
这是我的观点文件:
`<div class="card" ng-repeat="r in userBookingDetails">
<div class="list" >
<div class="item item-divider">
{{r.packagename}}
</div>
<label class="item item-input">
<div class="input-label col col-30">
Adults (Per Ticket) <span>Rs. {{r.adultprice}} </span>
</div>
<div class="input-label col col-20">
<button class="button button-calm mybtn" ng-click="decrement()">
-
</button>
</div>
<div class="input-label col col-30">
<input type="text" class="qty" />
</div>
<div class="input-label col col-20">
<button class="button button-calm mybtn" ng-click="increment()">
+
</button>
</div>
</label>
<label class="item item-input" ng-if="r.childprice!=0">
<div class="input-label col col-80">
Children (Per Ticket) <span>Rs. {{r.childprice}} </span>
</div>
<input type="number" name="" ng-model="userBookingDetails[$index].mobilechildqty" placeholder="0" value="0" class="col col-20" side="right" style="float:right;" >
</label>
</div>
</div>`