在AngularJS中,这失败并出现错误:
<my-directive ng-repeat="foo in foos" foo="foo" my-index="{{$index}}"/>
错误信息:
Error: [$parse:Syntax] Syntax Error: Token '$index' is unexpected,expecting [:] at column 3 of the expression [{{$index}}] starting at [$index}}].
这是指令:
app.directive('myDirective',function() { return { restrict: 'E',scope: { foo: '=',myIndex: '=' },templateUrl: 'directives/myDirective.html' }; });
这似乎只是自定义指令的问题.如果我试试这个:
<div ng-repeat="foo in foos" style="padding: {{$index}}px;"> index == {{$index}} </div>