AngularJS:ng-click不起作用

时间:2015-09-16 17:58:11

标签: angularjs angularjs-ng-click

我构建了一个函数,用于计算用户在users表中单击其名称的次数,但是ng-click不会触发该函数。

HTML code:

<tr ng-repeat="user in Users.slice(((currentPage-1)*itemsPerPage), ((currentPage)*itemsPerPage))">
     <td class="col-lg-1" ng-click="tapName(user.userName)">{{user.userName}}</td>
     <td class="col-lg-1">{{user.PassWord}}</td>
     <td class="col-lg-1">{{user.Name}}</td>
     <td class="col-lg-1">{{user.LastName}}</td>
     <td class="col-lg-1">{{$index}}</td>
     <td class="col-lg-1">{{user.countConnect}}</td>
     <td class="col-lg-1">{{user.countPaging}}</td>
     <td class="col-lg-1">{{user.countOrder}}</td>
     <td class="col-lg-1">{{user.countTapName}}</td>
</tr> 

AngularJS功能代码:

$scope.tapName = function(name){
    if($scope.User == name){
        $scope.User.countTapName ++;
    }
};

1 个答案:

答案 0 :(得分:1)

范围内没有User。范围包含Users,它是一组用户。您不应将用户名作为参数传递。你应该传递用户自己:

ng-click="tapName(user)"

$scope.tapName = function(user){
    user.countTapName++;
};