Angular: <select> and <options>
http://angularjs.org/
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.10/angular.js"></script>
<div ng-controller="MyCtrl as ctrl">
<div>selectedUnitOrdinal: {{ctrl.selectedUnitOrdinal}}</div>
<p>
1: <select ng-model="ctrl.selectedUnitOrdinal" ng-options="unit.id as unit.text for unit in ctrl.unitsOptions"></select>
I cannot get simple ordinal ID's to work. << NOW IT WORK
</p>
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.controller('MyCtrl', function() {
var self = this;
var unitOptionsFromServer = {
2: "mA",
3: "A",
4: "mV",
5: "V",
6: "W",
7: "kW"
};
self.unitsOptions = Object.keys(unitOptionsFromServer).map(function (key) {
return { id: +key, text: unitOptionsFromServer[key] };
});
self.selectedUnitOrdinal = 4;
});