如何通过评估的角度前pression修改的innerHTML [英] How to modify innerHTML by evaluating an angular expression
本文介绍了如何通过评估的角度前pression修改的innerHTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做这样的事情。
<div id="{{item.id}}" ng-repeat="item in itemList">
{{item.innerHTML}}
</div>
item.innerHTML包含需要去那里的HTML,但由于它是在DOM的一部分,它被替换为一个字符串。在那里,只是有它取代innerHTML的一种方式?
item.innerHTML contains the html that needs to go there, but since it is part of the dom, it is replaced as a string. Is there a way to just have it replace the innerHTML?
谢谢!
推荐答案
您需要使用ngBindHtml:
You need to use ngBindHtml :
<一个href=\"http://plnkr.co/edit/n1rLzgEZQoa2tJf0qnVZ?p=$p$pview\">http://plnkr.co/edit/n1rLzgEZQoa2tJf0qnVZ?p=$p$pview
在控制器:
$scope.content = "<b>this is bold content</b>";
HTML
<div ng-bind-html="content"></div>
您需要以下模块:
<一个href=\"http://$c$c.angularjs.org/1.0.3/angular-sanitize.js\">http://$c$c.angularjs.org/1.0.3/angular-sanitize.js
请务必声明ngSanitize作为一个模块依赖关系,例如:
Be sure to declare ngSanitize as a module dependancy, for instance :
var app = angular.module('angularjs-starter', ["ngSanitize"]);
这篇关于如何通过评估的角度前pression修改的innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文