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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With