Bind one property from object in object array

Description

The following code shows how to bind one property from object in object array.

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   w  w  w  . j  av a  2 s.  co m-->
app.controller('MainCtrl', function($scope) {
  $scope.users = [
    { firstName: 'J', lastName: 'J', email: 'j@example.com', sex:"Female"},
    { firstName: 'A', lastName: 'A', email: 'a@example.com', sex:"Female"},
    { firstName: 'S', lastName: 'S', email: 's@example.com', sex:"Male"},
    { firstName: 'K', lastName: 'K', email: 'k@example.com', sex:"Male"}
    ];
    
    $scope.getFullName = function(user) {
      return user.firstName + ' ' + user.lastName;
    };
});
  
  </script>
</head>
<body ng-controller="MainCtrl">
  <select ng-model="chosenUser" ng-options="user.email for user in users"></select>
  Selected User: {{ chosenUser }}
</body>
</html>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities