我有以下代码片段,它给了我解析错误。
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession(\"{{$index}}\")" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
我将\"{{$index}}\"
更改为this
后,就没有编译错误了。
知道为什么吗?谢谢。
更新1
基本问题是,我想将一些东西(可能是带有空格的字符串)传递给函数,但无法找到一种方法来做到这一点。下面的代码是一个天真的尝试,但它给出了 Angular 解析错误。
<!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>
最佳答案
您需要更新
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession(\"{{$index}}\")" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
至
<a class="pointer" role="menuitem" ng-repeat="rec in cfg.popupAssoc" ng-click="followSession($index)" tabindex="{{$index + 2}}"
{{rec.popupEntry}}
</a>
关于javascript - 使用 ng-repeat 解析 AngularJS 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31482704/