[英]how to pass value to an angular function using ng-click
I'm trying to pass the value of the ng-model="alertThreshold.value"
but when I click on <a class="spin-up" data-spin="up" ng-click = "getAlertThreshold(alertThreshold.value)"><i class="fa fa-caret-up"></i></a>
or <a class="spin-down" data-spin="down ng-click = "getAlertThreshold(alertThreshold.value)"" ><i class="fa fa-caret-down"></i></a>
it just call the function without updating the value, the value is always = 10. 我正在尝试传递
ng-model="alertThreshold.value"
的值,但是当我单击<a class="spin-up" data-spin="up" ng-click = "getAlertThreshold(alertThreshold.value)"><i class="fa fa-caret-up"></i></a>
或<a class="spin-down" data-spin="down ng-click = "getAlertThreshold(alertThreshold.value)"" ><i class="fa fa-caret-down"></i></a>
它只调用函数而不更新值,该值始终= 10。
<div class="input-group spinner" data-trigger="spinner">
<input type="text" class="form-control text-center" value="0" data-rule="quantity" ng-model="alertThreshold.value" min="0" max="50" ng-change ="getAlertThreshold(alertThreshold.value)">
<div class="input-group-addon">
<a class="spin-up" data-spin="up" ng-click = "getAlertThreshold(alertThreshold.value)"><i class="fa fa-caret-up"></i></a>
<a class="spin-down" data-spin="down" ng-click = "getAlertThreshold(alertThreshold.value)"><i class="fa fa-caret-down"></i></a>
</div>
</div>
and in my controller: 在我的控制器中:
$scope.alertThreshold = {
value: 10
};
$scope.getAlertThreshold = function(value){
console.log("value:",value)
$scope.alertThreshold.value = value;
}
The value of $scope.alertThreshold.value
is always the same because take the value of the input. $scope.alertThreshold.value
的值始终相同,因为采用输入值。 It's like $scope.alertThreshold.value = $scope.alertThreshold.value
every ng-click
or ng-change
就像
$scope.alertThreshold.value = $scope.alertThreshold.value
ng-click
或ng-change
$scope.alertThreshold.value = $scope.alertThreshold.value
ng-click =“ getAlertThreshold(++ alertThreshold.value)” ng-click =“ getAlertThreshold(-alertThreshold.value)”可解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.