我从服务器上得到了如下数据:
{
"pageIndex": 0,
"pageSize": 30,
"recordCount": 0,
"records": [
{
"auditContent": "",
"auditID": 354,
"auditStatus": 3,
"bizStatus": 1,
"bodyPart": "2",
"categoryID": 141,
"city": "上海",
"desc": "22",
"duration": 2,
"forbidden": "2",
"indications": "2",
"name": "<div><span style='color:red;'>头部</span></div>按摩"
}
]
}我使用Angular.js来显示HTML tag.Code的结果,如下所示:
<td ng-bind-html='spuWebDTO.name'></td>但是,它不起作用,我发现视图结果丢弃了<div><span style='color:red;'></span></div>标记.Only显示的文本:头部按摩
为什么和如何解决这个问题。
发布于 2016-07-25 05:54:35
嗨,你需要把ngSanitize添加到你的应用模块中,
`angular.module('bindHtmlExample', ['ngSanitize'])
.controller('ExampleController', ['$scope', function($scope) {
$scope.myHTML =
'I am an <code>HTML</code>string with ' +
'<a href="#">links!</a> and other <em>stuff</em>';
}]);`可以在模板中使用ng-bind-html。
<div ng-controller="ExampleController">
<p ng-bind-html="myHTML"></p>
</div>https://stackoverflow.com/questions/38560496
复制相似问题