如何编写类似于ngBindTemplate的指令,而不是接受作为模板的字符串,而是接受包含模板的变量?即:
现有:
ng-bind-template="{template}"
要编写:
ng-bind-compile="var"
where var="{template}"
提前感谢!
发布于 2013-06-13 09:33:08
下面是如何在指令的父作用域上下文中使用$compile
来完成此操作:
app.directive('ngBindCompile',function($compile){
return {
scope:{
template: '=ngBindCompile'
},
link: function(scope,element,attrs){
var html = '<div>' + scope.template + '</div>';
var compiled = $compile(html)(scope.$parent);
element.replaceWith(compiled);
}
}
});
https://stackoverflow.com/questions/17082027
复制相似问题