Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire a method after transclude has finished

I have an Angular directive that creates an accordion out of <ol> and <li> elements, with each <li>'s content being wrapped in a transcluded template. I need to fire a method to check if any of these <li> elements has an error, and open that accordion, but I can't find a way to fire the method after the elements have been transcluded.

Is there a hook or directive config that will time this correctly?

like image 616
b. e. hollenbeck Avatar asked Oct 28 '14 16:10

b. e. hollenbeck


1 Answers

I suppose you can access content in postLink function defined in directive definition object. Check official documentation.

Directive definition object enables you to define:

compile: function compile(tElement, tAttrs, transclude) {
  return {
    pre: function preLink(scope, iElement, iAttrs, controller) { ... },
    post: function postLink(scope, iElement, iAttrs, controller) { ... }
  }
  // or
  // return function postLink( ... ) { ... }
},

and there you can inject and access iElement and its content. This happens after template compilation so <li> elements should be already in place.

like image 174
tomastrajan Avatar answered Oct 14 '22 20:10

tomastrajan