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> 

plunker link

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

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -