0

Code in controller:

$scope.infoOptions = [
        { name: 'Select Option', value: '0' },
        { name: 'Some Option', value: '1' }
    ];

HTML:

<select data-ng-model="nothing" data-ng-options="info.name for info in infoOptions ">
    </select>

Angular puts that damn empty option at the top/selected by default. I've seen some answers to this question that suggest selecting a default option in the $scope for the form, but this select box is in a template in a dynamic form (ie. can be a number of select boxes). This is really only for demonstration purposes - is there anyway I can get rid of that empty option in a template?

  • You cannot update html template at all? Set ngmodel `nothing` to the first option possibly? – PSL Oct 10 '14 at 15:54
  • What would the syntax look like for that? I've tried ng-model="nothing = '0'", for example – Michael Anthopolous Oct 10 '14 at 15:55
  • You could do `$scope.nothing = $scope.infoOptions [0];` If you can edit the html, there are many options, you could use track by, you could use `select as` syntax and just set the model as value itself etc.. – PSL Oct 10 '14 at 15:58
  • Would you want to try something similar to this? http://plnkr.co/edit/6PR9Xu3Vq6ue1N9WEi4f?p=preview and then here is the option that @PSL suggested: http://plnkr.co/edit/UiJWdUMMdu9wGER99IlL?p=preview – BuddhistBeast Oct 10 '14 at 16:43
  • Thanks guys! Both options work. I'd give the green if I could, if someone wants to submit an answer :) – Michael Anthopolous Oct 10 '14 at 16:51
  • Possible duplicate of [Angular JS Remove Blank option from Select Option](https://stackoverflow.com/questions/20738953/angular-js-remove-blank-option-from-select-option) – Paul Sweatte May 25 '17 at 23:48

0 Answers0