如何通过评估角度表达式来修改innerHTML [英] How to modify innerHTML by evaluating an angular expression
问题描述
我正在尝试做这样的事情
{{item.innerHTML}}
item.innerHTML 包含需要去那里的 html,但由于它是 dom 的一部分,所以它被替换为一个字符串.有没有办法让它取代innerHTML?
谢谢!
你需要使用 ngBindHtml :
http://plnkr.co/edit/n1rLzgEZQoa2tJf0qnVZ?p=preview
在控制器中:
$scope.content = "这是粗体内容";
html:
<div ng-bind-html="content"></div>
您将需要以下模块:
http://code.angularjs.org/1.0.3/angular-消毒.js
确保将 ngSanitize 声明为模块依赖项,例如:
var app = angular.module('angularjs-starter', ["ngSanitize"]);
I am trying to do something like this
<div id="{{item.id}}" ng-repeat="item in itemList">
{{item.innerHTML}}
</div>
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?
Thanks!
You need to use ngBindHtml :
http://plnkr.co/edit/n1rLzgEZQoa2tJf0qnVZ?p=preview
in the controller :
$scope.content = "<b>this is bold content</b>";
html :
<div ng-bind-html="content"></div>
you'll need the following module :
http://code.angularjs.org/1.0.3/angular-sanitize.js
Be sure to declare ngSanitize as a module dependancy, for instance :
var app = angular.module('angularjs-starter', ["ngSanitize"]);
这篇关于如何通过评估角度表达式来修改innerHTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!