AngularJS Tutorial - Select model with initial value in scope








The following code shows how to select model with initial value in scope.

Example


<!DOCTYPE html>
<html  ng-app="myApp">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
  <script>
var app = angular.module('myApp', []);
<!--  w w  w . ja va  2  s. co m-->
app.controller('MainCtrl', function($scope) {
  $scope.sourceList = [
    {'id': '1', 'name': "A"},
    {'id': '2', 'name': "B"},
    {'id': '3', 'name': "C"}
  ];

  $scope.selectedItemExact = $scope.sourceList[0];
});  
  </script>
</head>
<body ng-controller="MainCtrl">


  <select ng-model="selectedItemExact" 
          ng-options="item.name for item in sourceList">
  </select> 
  {{selectedItemExact}}

  
</body>
</html>

The code above is rendered as follows: