Curriculum
Course: AngularJS
Login

Curriculum

AngularJS

AngularJS Tutorial

0/65
Text lesson

The Data Source as an Object

In previous examples, we used an array as the data source, but we can also work with an object that contains key-value pairs.

$scope.cars = {
  car01 : “Ford”,
  car02 : “Fiat”,
  car03 : “Volvo”
};

Example

When using an object as the data source, x represents the key, while y represents the value.

<select ng-model=”selectedCar” ng-options=”x for (x, y) in cars>
</select>

<h1>You selected: {{selectedCar}}</h1>

The selected value will always match the value in a key-value pair, which can also be an object.