Reputation: 5069
I have the following snippet and it gave me parsing error.
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession(\"{{$index}}\")" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
after I changed \"{{$index}}\"
to this
, it doesn't have the compile error.
Any idea why? Thanks.
UPDATE1
The basic problem is, I want to pass something (could be a string with white space) to a function, but can't figure a way to do it. The following code is a naive attempt but it gives angular parsing error.
<!DOCTYPE html>
<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr >
<td ng-click="dum();">ONE</td>
<td>TWO</td>
</tr>
<tr ng-repeat="x in names">
<td ng-click="dum({{x.Name}});" myid="{{$index + 1}}">{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
obj1 = "haha";
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers.php")
.success(function (response) {$scope.names = response.records;});
$scope.dum = function(x) { obj1 = x; console.log(x); }
});
</script>
</body>
</html>
Upvotes: 0
Views: 436
Reputation: 803
You can't use {{}} inside an ng-click. That is the cause of the parse error. Just remove them and it should work. The ng-repeat makes x available on scope. You don't have to wrap it in {{}} in this case.
Upvotes: 1
Reputation: 28475
You need to update from
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession(\"{{$index}}\")" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
to
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession($index)" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
Upvotes: 2