user1633149 user1633149 - 1 year ago 64
AngularJS Question

Angular component bindings objects not intialised

I am using angular 1.5 components in my project . In my component i always get undefined for the object data.

I hope the $ctrl.products are not initialized before calling the product-result component. How to call the product-result component only after initializing the

$ctrl.products objects.


<div class="container">
<div class="col-md-6" >
<product-result data="$ctrl.results" max="6"></product-result>


Answer Source

If you want to initialized the component after initialization of $ctrl.products then you can use $compile service which angular has provided.

Use the below line just after the line where $ctrl.products is getting initialized:

var domObj = $compile('<my-directive></my-directive>')($scope);
$('selector where you want to append this directive').append(domObj);