如何使用ng-click将值传递给角度函数

时间:2016-10-06 16:35:38

标签: javascript angularjs

我正在尝试传递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>

并在我的控制器中:

$scope.alertThreshold = {
        value: 10
    };

$scope.getAlertThreshold = function(value){
    console.log("value:",value)
    $scope.alertThreshold.value = value;
}

2 个答案:

答案 0 :(得分:0)

$scope.alertThreshold.value的值始终相同,因为获取输入的值。就像$scope.alertThreshold.value = $scope.alertThreshold.valueng-clickng-change

一样

答案 1 :(得分:0)

ng-click =“getAlertThreshold(++ alertThreshold.value)”ng-click =“getAlertThreshold( - alertThreshold.value)”可以解决问题。