2016-08-24 7 views
0

データ準備が整う前に、ngRepeatが表示される瞬間を検出する必要があります。initイベントを取得する

私はcompileを使用しようとしましたが(これはngRepeatに対して1回発生します)、運がまだありません。データが準備完了した後に起動します。

目的は、親ディレクティブにローディングスピナーを設定することです。それをデータ準備のために削除する。

私は子供の指示を検索するために親のポストリンクを使用することができますが、それは角の方法ではありません。

ここ
<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です:

は、ここで私はsomplyこのようなng-showディレクティブを使用することになり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の使い方ですか? OK。 – Kindzoku

+0

@ VassilisPits done as good – Kindzoku

答えて

関連する問題