[英]ng-change value not getting in angular controller
In html 在html中
<input type="number" min="0" max="1000" class="form-control" ng-model="eachvalue.hours" ng-change="updateHour(eachvalue);" placeholder="Hours" required>
In Controller 在控制器中
$scope.updateHour = function (val) {
console.log(val);
}
I m not getting the value of 10.100 on controller when changing the number text box , here i can only console the value of 10.1 更改数字文本框时,我未在控制器上得到10.100的值,在这里我只能控制台10.1的值
Can anyone know how to resolve the issue ????????? 谁能知道解决问题的方法吗?
By using ng-model
, the value is already (two-way-)bound to $scope.eachvalue.hours
. 通过使用
ng-model
,该值已经(双向)绑定到$scope.eachvalue.hours
。 It will always be up-to-date, no need to use ng-change and pass a value to it. 它将始终是最新的,无需使用ng-change并将值传递给它。
$scope.updateHour = function () {
console.log($scope.eachvalue.hours);
}
you can change your HTML also instaed 您也可以更改HTML
ng-change="updateHour(eachvalue)
TO 至
ng-change="updateHour(eachvalue.hours)
您可以尝试像这样定义eachvalue.hours,以便将其绑定:
$scope.eachvalue = { hours: 0 };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.