gpt4 book ai didi

javascript - Angular JS - 模型不更新数字输入字段

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:51 26 4
gpt4 key购买 nike

我有以下内容,而且我确信这里有一些我只是忽略的简单解决方案。我正在将数据加载到模型中,但它没有更新输入字段。

<div ng-app>
<h2>Testing</h2>
<div ng-controller="MyCtrl">
From: <input name="Price" type="number" ng-model='object.number["From"]' />
To: <input name="Price" type="number" ng-model='object.number["To"]' />
</div>
</div>

和 JavaScript:

function MyCtrl($scope) {
$scope.object = {number : {}};
$scope.object['number'] = {From: null, To: null}
console.log($scope.object['number']);

$scope.loadPrice = function(){
$scope.object['number'].From = "5";
$scope.object['number'].To = "5";
}

$scope.loadPrice();
console.log($scope.object['number'])

}

包括 fiddle :

http://jsfiddle.net/pCnfH/6/

最佳答案

您将输入限制为 type="number" 但将值设置为字符串:$scope.object['number'].To = "5";

因此您要么想将值设置为数字:

$scope.object['number'].From = 5;   
$scope.object['number'].To = 5;

updated fiddle

或者去掉数字限制:that fiddle

关于javascript - Angular JS - 模型不更新数字输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21149970/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com