データ準備が整う前に、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');
}
}
};
}
}
}
これは角度的な方法でもありません。あなたのコードをここに追加するか、助けを求めるプランナーを追加してください。 –
...何のプランカ? ngRepeatの使い方ですか? OK。 – Kindzoku
@ VassilisPits done as good – Kindzoku