我有一个类似的指令:
.directive('grapharea', function () {
return {
restrict:'C',
compile: function (element, attr) {
debugger;
//here attr.passed is graph_${{row.id}} instead of graph_1 or graph_2 ...
return function postLink(scope, element, attrs) {
};
}
};
})
这是我的ng-repeat代码:
<div ng-repeat="row in rows">
<div id="graph_{{$index}}" data-passed="{{row.passed}}" data-failed="{{row.failed}}" class="grapharea"></div>
</div>
问题:为什么我的指令中没有获得$ index值?
答案 0 :(得分:0)
编译函数对指令执行一次。我想你想使用链接函数,因为在编译指令时,每次使用指令只调用一次。