Seglespaan Seglespaan - 1 year ago 536
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?

Answer Source

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


ng-options="color in colors | unique:'name'"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download