角ng-绑定-html及其内的指令柱塞连杆我有一个元素,我想将html绑定到它。<div ng-bind-html="details" upper></div>这很管用。现在,除了它,我还有一个绑定到绑定html的指令:$scope.details = 'Success! <a href="#/details/12" upper>details</a>'但指令upper对DIV和锚不要进行评估。我该怎么做呢?
3 回答
慕哥6287543
TA贡献1831条经验 获得超10个赞
HTML:
<div compile="details"></div>
联署材料:
.directive('compile', ['$compile', function ($compile) {
return function(scope, element, attrs) {
scope.$watch(
function(scope) {
// watch the 'compile' expression for changes
return scope.$eval(attrs.compile);
},
function(value) {
// when the 'compile' expression changes
// assign it into the current DOM
element.html(value);
// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
}
);
};}])
慕姐4208626
TA贡献1852条经验 获得超7个赞
angular.module('vkApp')
.directive('compile', ['$compile', function ($compile) {
return function(scope, element, attrs) {
var ensureCompileRunsOnce = scope.$watch(
function(scope) {
// watch the 'compile' expression for changes
return scope.$eval(attrs.compile);
},
function(value) {
// when the 'compile' expression changes
// assign it into the current DOM
element.html(value);
// compile the new DOM and link it to the current
// scope.
// NOTE: we only compile .childNodes so that
// we don't get into infinite loop compiling ourselves
$compile(element.contents())(scope);
// Use un-watch feature to ensure compilation happens only once.
ensureCompileRunsOnce();
}
);
};}]);- 3 回答
- 0 关注
- 717 浏览
添加回答
举报
0/150
提交
取消
