有人可以简单解释一下吗?
文档似乎有点迟钝.我没有得到何时使用一个而不是另一个的本质和全局.两个对比的例子很棒.
HTML
<div repeater ng-repeat='item in items' class='first' id = '{{$index}}' > {{item}} </div>
Run Code Online (Sandbox Code Playgroud)
angularjs指令: -
angular.module('time', [])
.directive('repeater', function() {
var linkFn = function(scope, element, attrs){
var id = $(element).attr('id');
alert(id); // {{$index}}
} ...
Run Code Online (Sandbox Code Playgroud)
在ng-repeat中创建的动态id,当在指令内部显示为{{$ index}}时,而不是value = 0,1,2 ......
如何确保指令中的链接器函数执行时使用动态ID?我认为可以在指令中使用$ compile来完成.但我不知道怎么样?
$compile(element)(scope)
Run Code Online (Sandbox Code Playgroud)
是语法.但显然错误的顺序.
javascript angularjs angularjs-directive ng-repeat angularjs-ng-repeat