Search code examples
angularjsangularjs-ng-options

AngularJS: selecting option from dropdown menu


Here is my code:

<select class="form-control" name="author" ng-options="author as author.fullname for author in authors" ng-model="author" ng-required="true"></select>

How would I change selected value from controller?


Solution

  • Simply set the $scope.author to whatever author you want, for example:

    $scope.author = $scope.authors[2];
    

    Here is an example jsBin

    Or look up the author some how (by name, id?) and set the $scope.author or whatever to that value.