我有一個select
應該跟蹤myCoef
作爲浮點數值(不是一個對象,而是一個浮點值)。在AngularJs中初始化一個選擇
我有以下代碼(CodePen HERE):
function theController($scope) {
$scope.coefs = [
{name:'mm', val:1/1000},
{name:'cm', val:1/100},
{name:'m', val:1}
];
$scope.myCoef = 1/100;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js">
</script>
<body ng-app>
<div ng-controller="theController">
<select ng-model="myCoef"
ng-options="coef.name for coef in coefs track by coef.val">
</select>{{myCoef}}
</div>
</body>
如何正確初始化我select
,爲了保持在myCoef的浮點值?
{{myCoef.val}}? – Sajal
我希望將myCoef作爲** float **值,而不是一個對象。 – Serge