我需要在数据准备好之前检测到ngRepeat出现的时间。
我尝试过使用compile (它为ngRepeat触发一次),但仍然没有成功,它是在数据准备好之后才触发的。
目标是在parent指令上设置装入微调器。并在准备好的数据上删除它。
我想我可以使用父post链接来搜索孩子中的指令,但这不是angular的方式。
这是柱塞https://plnkr.co/edit/5OY5ySZm5L6Ba5Vw17af?p=preview
function testDirective(){
return {
compile: function compile(){
console.log('on data ready too, but I want it to be fired on init');
return {
pre: function(scope){
if(scope.$first){
console.log('first');
}
if(scope.$last){
console.log('last');
}
}
};
}
}
}发布于 2016-08-24 16:04:28
我会像这样使用ng-show指令:
<ul ng-controller="TestController as tc">
<li ng-show='tc.items' ng-repeat="item in ::tc.items">{{::item}}</li>
<div ng-show='!tc.items'>Loading...</div>
</ul>这是一个可以工作的柱塞。https://plnkr.co/edit/hOGlVZkmoMUyOOEskcnM?p=preview
如果你需要一些不太具体的东西,我可以作为一个包装器指令来做。
发布于 2016-08-24 16:07:50
找到了解决方案。在我的指令中使用priority: 1001。然后在ngRepeat之前编译触发。
这是一个有效的柱塞https://plnkr.co/edit/5OY5ySZm5L6Ba5Vw17af?p=preview
https://stackoverflow.com/questions/39117221
复制相似问题