2016-07-14 57 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> 
相关问题