2016-07-14 6 views
1

私はAngular 1.5を使用しています。以下に示すように、別のコンポーネントに埋め込まれたコンポーネントがあります。問題は、角膜炎がcomponent-childのときに変数dataがまだ解決されていないため、何も得られないということです。子コンポーネントがインスタンス化される前に変数が解決されるのを待つ方法コンポーネントをインスタンス化する前にデータが読み込まれるのを待ちます。

HTML

<component-parent> 
    <component-child data="$ctrl.data._id"><\component-child> 
</component-parent> 

JS

this.data = SomeResource.get(); 

答えて

4

ng-if

<component-parent> 
    <component-child ng-if="$ctrl.data._id" data="$ctrl.data._id"> </component-child> 
</component-parent> 
+1

私は複雑なライフサイクルの事を探していました。ダー! – Mika

+0

常にシンプルにしてください!それが助けてくれてうれしい。 – Chanthu

1

あなたはときにデータをロードするコンポーネントのコンパイルを延期するngIfを使用することができます。私たちについてどのように

Somesource.get().then(function(data) { 
    this.makeComponentVisible = true; 
}); 

<component-parent> 
    <component-child ng-if="$ctrl.makeComponentVisible" data="$ctrl.data._id"><\component-child> 
</component-parent> 
関連する問題