为什么我的指令中没有得到$ index值?

时间:2014-08-10 09:42:12

标签: 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(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值?

1 个答案:

答案 0 :(得分:0)

编译函数对指令执行一次。我想你想使用链接函数,因为在编译指令时,每次使用指令只调用一次。