Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular: ng-click with a parameter not working

Tags:

angularjs

I've got the following HTML:

<i style="cursor:pointer" ng-click="addName()" class="icon-plus"></i>
<i style="cursor:pointer" ng-click="delName({{$index}})" class="icon-remove"></i>

And the following functions in my controller's $scope:

$scope.addName = function() {
    $scope.names.push($scope.newName);
    $scope.newName = '';
};
$scope.delName = function(i) {
    $scope.names.splice(i, 1);
};

The addName() works fine but the delName() is never called. Is it impossible to bind an ng-clik to a function with an argument?

like image 661
plus- Avatar asked Feb 25 '13 12:02

plus-


1 Answers

The error was in the html, the ng-repeat $index should not be evaluated beforehand:

This is the valid HTML:

<i style="cursor:pointer" ng-click="delName($index)" class="icon-remove"></i>
like image 77
plus- Avatar answered Oct 12 '22 06:10

plus-