Ariel Livshits
Ariel Livshits

Reputation: 591

AngularJS: ng-click doesn't work

I built a function that counts how many times the user clicked on his name in the users table, but the ng-click doesn't triggers the function.

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 function code:

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

Upvotes: 0

Views: 818

Answers (1)

JB Nizet
JB Nizet

Reputation: 691635

There is no User in the scope. The scope contains Users, which is an array of users. You should not pass the user name as argument. You should pass the user itself:

ng-click="tapName(user)"

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

Upvotes: 1

Related Questions