0

I have my select dropdown and I couldn't select the default value from this dropdown in the controller.

<select ng-model="vm.userdataSet.userList" ng-options="option.value as option.displayName for option in 
vm.userOptions">
 <option value=""> --- Please select --- </option>
</select>
JSBeginner
  • 41
  • 2
  • 12

2 Answers2

1

If you've a similar data structure you can like something this, else provide your data code for more help you or look here: Working with select using AngularJS's ng-options

<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
    $scope.userOptions = ["Apple", "Windows", "Linux"];

    $scope.otherUserOptions = [
        { id: 1, name: 'foo' },
        { id: 2, name: 'bar' },
        { id: 3, name: 'blah' }
    ];

});
</script>

<!-- userOptions -->
<select ng-model="vm.userdataSet.userList" ng-options="item for item in userOptions">
 <option value=""> --- Please select --- </option>
</select>

<!-- otherUserOptions -->
<select ng-model="vm.userdataSet.userList" ng-options="item as item.name for item in otherUserOptions">
 <option value=""> --- Please select --- </option>
</select>
Nevada
  • 143
  • 1
  • 10
1

Check below code take reference from this working example:

  <div ng-app>
    <div ng-controller="DemoSetDefaultCtrl">
      <div ng-hide="editorEnabled">
        {{title}}

      </div>
      <div>
        <select name="type" ng-model="user" ng-dropdown required ng-options="option.type for option in options">
          <option value=""> --- Please select --- </option>
        </select>
      </div>
    </div>
  </div>
  <script>
    function DemoSetDefaultCtrl($scope) {
      $scope.title = "Set Default Value";

      $scope.options = [
        { type: 'User 1' },
        { type: 'User 2' },
        { type: 'User 3' },
        { type: 'User 4' }
      ];
      $scope.user = $scope.options[1];
    }
  </script>
Viral Patel
  • 1,104
  • 4
  • 7