angularjs – 自定义指令中的ng-repeat:语法错误:令牌’$index
发布时间:2020-12-17 17:48:54 所属栏目:安全 来源:网络整理
导读:在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}}] st
在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> 解决方法
由于您使用=来声明隔离的范围属性,因此Angular期望一个未插值的属性:
为了将$index值作为内插值更改为@注入: scope: { foo: '=',myIndex: '@' }, 然后使用: <my-directive ng-repeat="foo in foos" foo="foo" my-index="{{$index}}"/> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |