我正在使用一个angularjs示例工作,我面临一个问题是我已经加载了html视图,然后在一个div之后是来自controler(数据库调用)的内容html数据,也像这样的数据内容html标签,<hr> <images>
但显示的不是渲染html,所以我想渲染该html部分。
我知道我的问题是延迟的数据来自数据库,因此将作为计划文本支付。
我使用ng-bind-html
直到它们显示痛苦的文本而不呈现html标签。
我有一个答案是延迟页面加载可以成功进行,但是这不是bcoz有时数据库数据可能需要很长时间才能在这种情况下无法正常工作的正确方法。
嗨,周杰伦,您必须为示例创建指令,即名称bind-unsafe-html在其中传递html字符串或内容,然后它将重新呈现html内容。例如。
app.directive('bindUnsafeHtml', ['$compile', function ($compile) {
return function(scope, element, attrs) {
console.log("in directive");
scope.$watch(
function(scope) {
// watch the 'bindUnsafeHtml' expression for changes
return scope.$eval(attrs.bindUnsafeHtml);
},
function(value) {
// when the 'bindUnsafeHtml' 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);
}
);
};
}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句