uiLimitTo is an alternative of Angular's limitTo
to ensures that the model is in the input resource.
===
- Using bower
bower install ui-limit-to --save
- Not using any package manager
Just copy thebuilds/release/uiLimitTo.js
script to your project.
===
- Load the script in your index.html
<script src="bower_components/uiLimitTo/builds/release/uiLimitTo.js"></script>
- Load the module as dependence
angular.module('YourModule', ['uiLimitTo']);
<div ui-select ng-model="myModel">
<div ui-select-match placeholder="'Select'">
<span ng-bind="$select.selected.name"></span>
</div>
<div ui-select-choices
repeat=" item in list | filter: $select.search | uiLimitTo:100:myModel:'id' track by item.id ">
<div ng-bind-html="item.name | highlight: $select.search"></div>
</div>
</div>
var list = [{ id: 1 }, { id: 2 }, { id: 3 }],
maxLimit = 2,
myModel = { id: 3 },
compareBy = 'id';
$filter('uiLimitTo')(list, maxLimit, myModel, compareBy);
// -> [{ id: 1 }, { id: 3 }]
===
Param | Type | Details |
---|---|---|
input | `Array | ArrayLike |
limitNumber | Number |
The length of the returned array or string. If the limit number is positive, limit number of items from the beginning of the source array/string are copied. If the number is negative, limit number of items from the end of the source array/string are copied. The limit will be trimmed if it exceeds array.length. If limit is undefined, the input will be returned unchanged. |
model | `Object | String |
modelProperty | String |
specifies the property to be compared when search the model in the list. |
begin | Number |
Index at which to begin limitation. As a negative index, begin indicates an offset from the end of input. |
options | Object |
Additional options like options.comparator |
{Array|ArrayLike|String|Number}
The same type of input argument.