2016-07-14 81 views
1

我正在使用Angular 1.5。我有一個組件嵌入到另一個組件中,如下所示。問題是,data變量尚未解決時,角火災component-child,所以我什麼也沒有得到。如何在子組件實例化之前等待變量被解析。在實例化組件之前等待數據加載

HTML

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

JS

this.data = SomeResource.get(); 

回答

4

怎麼樣我們ing 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> 
相關問題