angularjs - ng-option showing two empty options while group by empty value -
i have made dropdown ng-option , added grouping. data contains empty string opting on have added grup by. show 2 empty nodes in dropdown. need remove 2 empty nodes dropdown
angular.module('selectexample', []) .controller('examplecontroller', ['$scope', function($scope) { $scope.colors = [{ name: 'black', shade: '' }, { name: 'white', shade: 'light', notanoption: true }, { name: 'red', shade: 'dark' }, { name: 'blue', shade: 'dark', notanoption: true }, { name: 'yellow', shade: 'light', notanoption: false }]; $scope.mycolor = $scope.colors[2]; // red }]);
html:
<select ng-model="mycolor" ng-options="color.name group color.shade color in colors"> </select>
you can remove empties shades of colors.
just include in controller:
$scope.colors = $scope.colors.map(function(value) { if (value.shade == '') { value.shade = undefined; } return value; });
Comments
Post a Comment