This is my code, based here. limitTo is dynamic and gets its value from user input.
<script>
var monthly=[123.659855, 89.645222, 97.235644, 129.555555];
function MyFilterDemoCtrl($scope) {$scope.monthly= monthly;};
</script>
<body ng-controller="MyFilterDemoCtrl" >
Num: <input ng-model="num" type="text" />
<li ng-repeat="gigabytes in monthly | limitTo:num"> {{ gigabytes}} </li>
<body>
I was wondering how can I alter the limitTo filter like this
<li ng-repeat="gigabytes in monthly | limitTo:monthly.lenght() OR num">
so when the page loads (input is empty) all the items of the array are displayed and when user types a number, the proper amount of items is displayed.
(page loads, all items displayed, then user types 3, only the first 3 items appear)
To make it "perfect" I would like to know how I can print a message to the user when the input exceeds the array lenght.
Thanks in advance
EDIT
Code as it is now , cannot display all items, and then redisplay user input. The only way to display all when page loads is to do
gigabytes in monthly track by $index | limitTo:num
but then the user input has no effect. I use angular 1.2.28. I dont actually get the concept of track by $index. Thanks again
monthly.lenght().limitTo:num || monthly.length