angularjs - how to give maximum selected element in angular js? -
can give maximum selected element limit in angular ?actually have 1 multiple selected element in user can select multiple thing .but need restrict user in other other user select 3 items them .i tell problem again have on button .on click of button show pop in user select multiple element .i need user select maximum 3 .if try select 4 element gives error can't select more 3 can in angular ?
here code http://codepen.io/anon/pen/jpypnb.
angular.module('ionicapp', ['ionic']) .controller('mycontroller', function($scope, $ionicpopover) { $scope.data =[ {"name":"a", value:false}, {"name":"b", value:false}, {"name":"c", value:false}, {"name":"d", value:false}, {"name":"e", value:false} ] $ionicpopover.fromtemplateurl('my-popover.html', { scope: $scope }).then(function(popover) { $scope.popover = popover; }); $scope.openpopover = function($event) { $scope.popover.show($event); }; $scope.closepopover = function() { $scope.popover.hide(); }; } )
add control on max value on button click
see updated code here http://codepen.io/anon/pen/jpypnb?editors=001
the process here :
$scope.maxcheck = function($index){ $scope.countmax = 0; for(i=0;i<$scope.data.length;i++){ if($scope.data[i].value == true) $scope.countmax++; } console.log("calc",$scope.countmax,$scope.max) if($scope.countmax > $scope.max){ $scope.data[$index].value = false; alert("limit reached"); }
Comments
Post a Comment