0
裏面我需要在NEWVALUE的HTML工作,但它似乎只是吐出逃脫charaters傳遞的HTML模板角指令
.directive('ngLookup', function() {
return {
restrict: 'A',
scope : {
text : '='
},
template: '{{newValue}}',
link: function (scope, elem, attrs) {
scope.newValue = scope.text.replace(/test/g,'<a href="javascript:;">test</a>');
}
}
})
使用下面的答案我的解決辦法:
.directive('ngLookup', function ($compile) {
return {
restrict: 'EA',
scope : {
text : '='
},
link: function (scope, elem, attrs) {
var txt = '<span>'+scope.text.replace(/test/g,'<a href="javascript:;">test</a>')+"</span>";
var newElement = $compile(txt)(scope);
elem.replaceWith(newElement);
}
}
})
這工作。非常感謝。 –