在动态ng-include模板中注入HTML

时间:2014-01-22 22:00:07

标签: angularjs

我有以下指令

...
template: <div ng-include={{model.template}} \>
...

模板是动态的。我想通过指令链接或编译阶段在该模板中注入额外的HTML。我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用函数将模板作为字符串返回:

function resolveTemplate(tElement, tAttrs) {

}

angular.module('MyApp').directive('maybeLink', function() {
  return {
    //...
    template: resolveTemplate,
    //...
  }; 
});

请参阅此答案以获取更多详细信息:https://stackoverflow.com/a/21105774/149060