Javascript 为什么我没有在指令中获得$index值?
我有一个类似这样的指令:Javascript 为什么我没有在指令中获得$index值?,javascript,angularjs,Javascript,Angularjs,我有一个类似这样的指令: .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
.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重复代码:
<div ng-repeat="row in rows">
<div id="graph_{{$index}}" data-passed="{{row.passed}}" data-failed="{{row.failed}}" class="grapharea"></div>
</div>
问题:为什么我没有在指令中获取$index值?编译函数对指令执行一次。我认为您希望使用link函数,因为在编译指令时,每次使用该指令只调用一次link函数