how can use ng-options populate select element results of "categories" arrays, within objects?
{ title: "star wars", categories: ["coding", "exploration", "adventure"] }, { title: "street wars", categories: ["surfing", "exploration", "testing"] }, i want populate select element available categories, , use "unique" filter out duplicate entries...
as comment says, it's easier create unique part in controller, , use ngoptions on new array:
$scope.uniqueoptions = []; (var = 0; < data.length; i++) { (var j = 0; j < data[i].categories.length; j++) { if ($scope.uniqueoptions.indexof(data[i].categories[j]) === -1) { $scope.uniqueoptions.push(data[i].categories[j]) } } } and options:
<select ng-model="somemodel" ng-options="category category category in uniqueoptions"> </select>
Comments
Post a Comment