0

I just have a static select list with 2 options so I didn't use the ng-options parameter. This works only if the user does something to the dropdown. If they leave the value as-is, the dataItem comes through as undefined.

<select ng-model="dataItem.Options">
    <option value="1" ng-selected="selected">1</option>
    <option value="2">2</option>
</select>

How can I just use the default value, or why isn't my unchanged dropdown passing a value back to my controller? I've also tried to use ng-init="1" in the select tag, but that doesn't seemt to work either.

fischgeek
  • 688
  • 1
  • 5
  • 18

1 Answers1

0

You'll need to set dataItem.Options to the value you want to select

     $scope.dataItem = {Options: '1'};

Note that the value is a string, '1', and not the number 1. THen you can remove the ng-selected.

Scott
  • 1,690
  • 3
  • 13
  • 18
  • That worked. I just had to wrap it in an if (!dataItem.Options) check first, but it does the job! Thank you! – fischgeek Dec 29 '15 at 16:08