Angular 更新不带引号的 ng-model
Angular update ng-model without quotations marks
这是我的代码:
JS:
$scope.gamma = {
0 : 2
};
$scope.matrix = {
1 : 21, 2 : 25, 3 : 21, 4 : 85, 5 : 798, 6 : 4, 7 : 51, 8 : 224, 9 : 63
};
$scope.update_layers = function(gamma, gvalue, matrix, mvalue){
$scope.gamma = gamma;
if(gvalue){
$scope.gamma.gvalue = parseInt(gvalue)
for(var i in $scope.gamma){
$scope.gamma[i] = parseInt($scope.gamma[i]);
}
}
if(mvalue){
$scope.matrix.mvalue = parseInt(mvalue)
}
HTML:
{{gamma}}{{matrix}}
<br />
gamma : <span ng-repeat="(g, value) in gamma"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="gamma[g]"></span>
<br />
matrix : <span ng-repeat="(m, value) in matrix"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]"></span>
<button class="btn" ng-click="update_layers(gamma, gamma.value, matrix, matrix.value)">update</button>
我想展示:
"1":21
而不是 "1":"21"
这是我的 plnkr 和我的努力:
http://plnkr.co/edit/LFvqgeCtOWv4OGxiDDuY?p=preview
将 type="number"
添加到您的输入字段。例如
<input type="number" class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]">
这是我的代码: JS:
$scope.gamma = {
0 : 2
};
$scope.matrix = {
1 : 21, 2 : 25, 3 : 21, 4 : 85, 5 : 798, 6 : 4, 7 : 51, 8 : 224, 9 : 63
};
$scope.update_layers = function(gamma, gvalue, matrix, mvalue){
$scope.gamma = gamma;
if(gvalue){
$scope.gamma.gvalue = parseInt(gvalue)
for(var i in $scope.gamma){
$scope.gamma[i] = parseInt($scope.gamma[i]);
}
}
if(mvalue){
$scope.matrix.mvalue = parseInt(mvalue)
}
HTML:
{{gamma}}{{matrix}}
<br />
gamma : <span ng-repeat="(g, value) in gamma"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="gamma[g]"></span>
<br />
matrix : <span ng-repeat="(m, value) in matrix"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]"></span>
<button class="btn" ng-click="update_layers(gamma, gamma.value, matrix, matrix.value)">update</button>
我想展示:
"1":21
而不是 "1":"21"
这是我的 plnkr 和我的努力:
http://plnkr.co/edit/LFvqgeCtOWv4OGxiDDuY?p=preview
将 type="number"
添加到您的输入字段。例如
<input type="number" class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]">