JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://code.angularjs.org/1.2.9/angular.js"></script>
<body ng-app ng-controller="AppCtrl">
<p>I would like to use ng-repeat with select options and keep the selected car as object and not a json.</p>
<select
ng-model="selectedCar"
ng-options="car as car.name for car in cars track by car.id">
</select>
<h3>With ng-options without converting</h3>
<pre>{{selectedCar.id}}</pre>
<pre>{{selectedCar.name}}</pre>
<select ng-model="selectedCar2">
<option value=""></option>
<option
ng-repeat="car in cars"
value="{{car}}"
title="{{car.name}}">{{car.name}}
</option>
</select>
<h3>With ng-repeat without converting</h3>
<pre>{{selectedCar2.id}}</pre>
<pre>{{selectedCar2.name}}</pre>
<h3>With ng-repeat with converting</h3>
<pre>{{carToObject(selectedCar2).id}}</pre>
<pre>{{carToObject(selectedCar2).name}}</pre>
</body>
JavaScript
function AppCtrl($scope) {
$scope.cars = [
{id: 10, name: 'Ferrari'},
{id: 15, name: 'Dodge'}
]
$scope.carToObject = function(jsonCar) {
return angular.fromJson(jsonCar);
}
}