angularjs - How to remove duplicate options from angular ui select? -
here angular ui select html:
<ui-select title="select template directory" ng-change="searchtemplate()" theme="select2" ng-model="search_data.sub_directory" id="search_sub_directory" name="search_sub_directory" class="search_panel"> <ui-select-match allow-clear="true" placeholder="select template directory">{{$select.selected.subdirectory}}</ui-select-match> <ui-select-choices repeat="template.subdirectory template in response_template_directories | filter: $select.search"> <span ng-bind-html="template.subdirectory | highlight: $select.search"></span> </ui-select-choices> </ui-select>
and here response_template_directories
[ {subdirectory : 1}, {subdirectory : 1}, {subdirectory : 1}, {subdirectory : 1}, {subdirectory : 1}, {subdirectory : 1}, {subdirectory : 2}, {subdirectory : 3}, ]
select list showing duplicates
how can remove these duplicates in ui select html?
use filter unique (implement angularui or import a8m/angular-filter).
<ui-select title="select template directory" ng-change="searchtemplate()" theme="select2" ng-model="search_data.sub_directory" id="search_sub_directory" name="search_sub_directory" class="search_panel"> <ui-select-match allow-clear="true" placeholder="select template directory">{{$select.selected.subdirectory}}</ui-select-match> <ui-select-choices repeat="template.subdirectory template in response_template_directories | unique: 'subdirectory' | filter: $select.search"> <span ng-bind-html="template.subdirectory | highlight: $select.search"></span> </ui-select-choices>
or write own filter lodash:
app.filter('unique', function() { return function (arr, field) { return _.uniq(arr, function(a) { return a[field]; }); }; });
Comments
Post a Comment