2016-08-24 57 views
0

在數據準備就緒之前,我需要檢測一個出現ngRepeat的時刻。Catch ngRepeat初始化事件

我試過使用compile(它爲ngRepeat啓動一次),但仍然沒有運氣,它在數據準備好後觸發。

目標是在父指令上設置加載微調器。並在數據準備就緒時將其刪除。

猜測我可以使用父郵件鏈接來搜索孩子的指令,但它不是角度的方式。

這裏是plunker 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'); 
         } 
        } 
       }; 
      } 
     } 
    } 
+0

這也不是角度的方式。在此處添加您的代碼或者獲得幫助。 –

+0

......這是什麼? ngRepeat的用法?好。 – Kindzoku

+0

@VassilisPits一樣好 – Kindzoku

回答

0

我會somply使用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> 

這裏是一個工作plunker。 https://plnkr.co/edit/hOGlVZkmoMUyOOEskcnM?p=preview

如果你需要一些不太具體的東西,我可以做爲包裝指令。

+0

但我仍然需要範圍變量。 – Kindzoku