Reputation: 1632
I'm creating a directive within another parent directive and then appending the directive's compiled element to the parent directive's node. $compile(template)(scope) correctly creates the directive, but the link function is not being called.
var addProductsToPage = function(template, products) {
for (var i = 0 ; i < products.length ; i++) {
var product = products[i];
var productScope = $scope.$new(true);
productScope.product = product
var productDirective = $compile(template);
var productElement = productDirective(productScope);
element.append(productElement);
}
}
How do I call the link function after I compile the template?
Upvotes: 0
Views: 952
Reputation: 276085
$compile(template)
actually returns the link function.
So productDirective(productScope)
is actually the call to the link function.
Source : http://docs.angularjs.org/api/ng.$compile
Returns {function(scope[, cloneAttachFn])} – a link function which is used to bind template (a DOM element/tree) to a scope
Upvotes: 4