javascript - Set selected drop down option in Angular JS -


i have drop down list of results.

<div ng-app="myapp" ng-controller="myctrl">  <select ng-model="selectedname" ng-options="item.value item in names track item.id"> </select>  </div>  <script> var app = angular.module('myapp', []); app.controller('myctrl', function($scope) {     $scope.names = [         {"id":1,"value":"nhq"},         {"id":2,"value":"chapter"},         {"id":3,"value":"other"}     ]; 

now want pro grammatically set selected item value in drop down .

still initialized blank.

i did :

$scope.selectedname = "other"; 

but apparently did not work. missing ?

p.s. $scope.selectedname can set . trial , simplified version of problem.

use $scope.selectedname = $scope.names[2]; since names array of object , need provide select object set default.

var app = angular.module('myapp', []);  app.controller('myctrl', function($scope) {      $scope.names = [          {"id":1,"value":"nhq"},          {"id":2,"value":"chapter"},          {"id":3,"value":"other"}      ];     $scope.selectedname = $scope.names[2];  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div ng-app="myapp" ng-controller="myctrl">    <select ng-model="selectedname" ng-options="item.value item in names track item.id">  </select>    </div>


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -