0

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?

2
  • I´m afraid not. I already had a similar requirment and couldnt find a better solution then using the $compile-Function. As for the performance: I´m not really sure if it decreases the performance that much - since Angular would do the same thing if you would provide it with a templateUrl-Property. Commented Mar 24, 2014 at 18:50
  • yeah, but if I'm not mistaken, it does it twice, once during it's own compile and then again when it's ready in link function.. which also means it start compiling when everything else is ready, so it has to be somewhat slow.. I think.. unless it doesn't compile when you don't provide template.. which would make sense I guess Commented Mar 24, 2014 at 19:00

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.