Jquery 我无法在桌体内选择带有ng REPECT的tr?

Jquery 我无法在桌体内选择带有ng REPECT的tr?,jquery,angularjs,ng-repeat,Jquery,Angularjs,Ng Repeat,我试图用angularjs为表编写一个指令,但选择table>tr只会产生表的第一行。结果中不包括tr的内部tbody。当我从此语句中删除headers中的ng repeat=header时 <table> <thead> <tr> <th ng-repeat="header in headers">{{header}}</th> </tr> </

我试图用angularjs为表编写一个指令,但选择table>tr只会产生表的第一行。结果中不包括tr的内部tbody。当我从此语句中删除headers中的ng repeat=header时

<table>
    <thead>
        <tr>
            <th ng-repeat="header in headers">{{header}}</th>
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="header in headers">   // I removed ng-repeat to select all rows
            <td ng-repeat="header in headers">{{header}}</td>
        </tr>
    </tbody>
</table>
已成功选择表的所有行。我可以通过console.log看到四个tr对象。如何在指令链接函数中选择表内的所有行?谢谢你抽出时间

这是我的plnk:

似乎指令在ng repeat完成之前加载。 我将您的代码移到$timeout中,我看到它正在工作

$timeout(function(){
    console.log(element.find('tr'));
    console.log(element.find('tr').length);
},1000);
您需要注入$timeout以使其正常工作:

directives.directive('zenTable', function($compile,$timeout) {
但不确定这是否是一种理想的方法

compile : function($element, $attrs){
    return function(scope,element,attrs){
        setTimeout(function() {
             console.log(element.find('tbody').children());
        },100);

    };
}
将代码移动到超时功能