Mika Mika - 4 months ago 27
AngularJS Question

Wait for data to load before instantiating a component

I am using Angular 1.5. I have a component embedded in another component as demonstrated below. Problem is that the

data
variable is not yet resolved when angular fires
component-child
and so I get nothing. How do I wait for the variable to be resolved before the child component instantiates.

html

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


js

this.data = SomeResource.get();

Answer

How about using ng-if?

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