javascript - ng-repeat limit make issue for remove -
i have 1 ng-click add md-datepicker :
<md-button ng-click="additem()" type="button" >add infants</md-button>
then ng-repeat set 4 :
ng-repeat="d in radiodata | limitto: 4 " ng-value="d.value" ng-class="{'md-align-top-left': $index==1}"
everything working expected have 1 ng-click remove:
<md-button ng-click="removeitem()" type="button">remove infants</md-button>
then problem start if click more 4 time on additem() not show remove start remove first kind of wierd. there not show . read track $index
not working . controller is:
$scope.additem = function() { $scope.radiodata.push({}); }; $scope.removeitem = function() { $scope.radiodata.pop(); };
any idea me
when call additem()
, push new struct radiodata
. however, you're limiting shown data 4 items via limitto:4
through ng-repeat
. means can still add more 4 items radiodata
array, won't shown ng-repeat
. thus, when remove elements after adding more 4 items radiodata
array, still have more 4 items in radiodata
array.
you can fix limiting number of items allowed exist in radiodata
array, follows:
$scope.additem = function() { if ($scope.radiodata.length < 4) { //check there space new struct $scope.radiodata.push({}); } };
Comments
Post a Comment