I made a template for each table - 5 total - and then passed the relative url of the template I wanted as an attribute to the directive. So it worked out like this:
<ea-children details="childrenFirst" template-url="/templates/first.html"></ea-children>
<ea-children details="childrenSecond" template-url="/templates/second.html"></ea-children>
<ea-children details="childrenThird" template-url="/templates/third.html"></ea-children>
As you can see I was able to reuse the same directive three times with potentially drastically different markup. The templateUrl function looks like this:
templateUrl: function (element, attributes) {
return attributes.templateUrl;
}
One major item to note is that you don't have access to scope variables because the template is requested before scope is initialized.
Hopefully next time I need to do this (assuming I'm still using Angular 1.x) I'll remember to check here first. Happy coding!
No comments:
Post a Comment