Select model with initial value in scope

Description

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', []);
<!--from ww w  . j  a 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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities