Seglespaan Seglespaan - 4 months ago 107x
AngularJS Question

angular.js using ng-options to only display unique values

If I have an array

$scope.colors = [
{name:'black', shade:'dark'},
{name:'white', shade:'light'},
{name:'red', shade:'dark'},
{name:'red', shade:'dark'},
{name:'yellow', shade:'light'}


Is it possible to use ng-options to build a select element with only unique values in the dropdown, so red will only display once?


AngularUI has exactly what you need, the ´unique´ filter (src code).


ng-options="color in colors | unique:'name'"