I'm trying to write some application using ng-repeat and limitTo, but it seems that the input field and the buttons can't work together on the same model value.
The problem is that once I changed the value from the input field, the buttons won't work any more. could you tell me why?
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
'Jani',
'Carl',
'Margareth',
'Hege',
'Joe',
'Gustav',
'Birgit',
'Mary',
'Kai'
];
$scope.test = 3;
$scope.dPlus = function(){
$scope.test++;
}
$scope.dMinus = function(){
$scope.test--;
}
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body ng-app="myApp" ng-controller="namesCtrl">
<div ng-if='true'>
<p>Type a number in the input field:</p>
<p><input type="number" ng-model="test"></p>
<input type="button" value="+" ng-click="dPlus()"/>
<input type="button" value="-" ng-click="dMinus()"/>
<div>{{ test }}</div>
<ul>
<li ng-repeat="x in names | limitTo:test">
{{ x }}
</li>
</ul>
</div>
</body>
</html>