A previous blog post I wrote ('How to build a UI without seeing the data'), investigated building dynamic user interfaces. The approach I demonstrated used a directive in which a template was assigned based on a data type. Below is the code snippet from the previous post.
Here; the template contains an ng-include which returns a value from a function. This does indeed work as expected, however, there may be some performance issues due to this setup. Anytime scope changes, the getContentUrl function will be re-run performing any potential function logic. Any ng attribute calling a function will do the same.
If we change the above directive to:
Now we are assigning the templateUrl to a scope variable instead of a function. If scope is changed, it just has to look to see if this variable has changed instead of running a function which may have to perform logic.
In the end, both approaches accomplish the same result but we have to be cognizant of performance when building large applications. Every little bit helps.