AngularJS directive dynamic templates

You can set the template property of your directive definition object to a function that will return your dynamic template:

restrict: "E",
replace: true,
template: function(tElement, tAttrs) {
    return getTemplate(tAttrs.content);
}

Notice that you don’t have access to scope at this point, but you can access the attributes through tAttrs.

Now your template is being determined before the compile phase, and you don’t need to manually compile it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)