0

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 ++;
    }
};

1 Answer 1

1

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++;
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.