問題:使用ng-bind-html 頁面上已經產生了正確的html程式碼,但是標籤中的 指令 不生效!
js程式碼:
#html程式碼:
#
怪我咯2017-06-16 09:21:14
當然無法生效,ng-bind-html
等同於 innerHTML
。
可以自訂一個類似 ng-bind-html-compile
的指令:
.directive('bindHtmlCompile', ['$compile', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(function () {
return scope.$eval(attrs.bindHtmlCompile);
}, function (value) {
// In case value is a TrustedValueHolderType, sometimes it
// needs to be explicitly called into a string in order to
// get the HTML string.
element.html(value && value.toString());
// If scope is provided use it, otherwise use parent scope
var compileScope = scope;
if (attrs.bindHtmlScope) {
compileScope = scope.$eval(attrs.bindHtmlScope);
}
$compile(element.contents())(compileScope);
});
}
};
}]);
<p ng-bind-html-compile="getId(xxx)"></p>