Angular: ng-click with idle option
I have 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 $scope controller:
$scope.addName = function() { $scope.names.push($scope.newName); $scope.newName = ''; }; $scope.delName = function(i) { $scope.names.splice(i, 1); }; addName() works fine, but delName() never called. Is it impossible to associate ng-clik with a function with an argument?
+7
plus-
source share3 answers
The error was in html, the ng-repeat $ index should not be pre-evaluated:
This is valid HTML:
<i style="cursor:pointer" ng-click="delName($index)" class="icon-remove"></i> +14
plus-
source shareIt seems to me that this code suits me, can you isolate your problem in jsFiddle?
EDIT: Removed incorrect answer about splicing not modifying an array.
0
Anders Ekdahl
source shareYou can do the following:
<i ng-click="delName($index)" class="icon-remove"></i> In css
[ng-click], [data-ng-click], [x-ng-click] { cursor: pointer; } 0
Fizer khan
source share