In AngularJS, this happens with an error:
<my-directive ng-repeat="foo in foos" foo="foo" my-index="{{$index}}"/>
Error message:
Error: [$parse:syntax] Syntax Error: Token '$index' is unexpected, expecting [:] at column 3 of the expression [{{$index}}] starting at [$index}}].
Here's the directive:
app.directive('myDirective', function() {
return {
restrict: 'E',
scope: { foo: '=', myIndex: '=' },
templateUrl: 'directives/myDirective.html'
};
});
This is only a problem with custom directives. If I try this:
<div ng-repeat="foo in foos" style="padding: {{$index}}px;">
index == {{$index}}
</div>
source
share