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>

2 Answers 2

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>
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.