1
如何將一個指令類似於ngBindTemplate,但不是採取一個字符串,它是模板,採用包含模板,即一個變量:如何編寫ngBindCompile指令?
Existing: ng-bind-template="{template}" To write: ng-bind-compile="var" where var="{template}"
提前感謝!
如何將一個指令類似於ngBindTemplate,但不是採取一個字符串,它是模板,採用包含模板,即一個變量:如何編寫ngBindCompile指令?
Existing: ng-bind-template="{template}" To write: ng-bind-compile="var" where var="{template}"
提前感謝!
這是怎麼會在指令中的父範圍的環境中使用$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);
}
}
});
感謝您的幫助! – zcaudate