Angular.js directive template using variable from

2019-09-02 16:39发布

问题:

I want to chose directives templateUrl depending on some variable from its parent scope. I can't use templateUrl function, since it doesn't have a scope yet. I can $compile the template from $templateCache(note that it's already there, I'm not loading it) from inside the linking function, but I am afraid it's gonna have a negative impact on performance(let say this is a table cell directive.. and there's quite a few cells).

Do I have any other, better option?

回答1:

There is indeed no other way around. Although you should $compile this way to achieve somewhat satisfactory performance results. https://stackoverflow.com/a/22646392/301596