Angularjs $sce.trustAsHtml不工作
我正在从RESTAPI获取帖子内容。 我得到的内容是:“Angularjs $sce.trustAsHtml不工作,angularjs,plaintext,ng-bind-html,Angularjs,Plaintext,Ng Bind Html,我正在从RESTAPI获取帖子内容。 我得到的内容是:“ptest post body/;p” 首先,我分析纯文本 data[i].postBody = $sce.trustAsHtml(data[i].postBody); 在我这样做并尝试使用ng bind html显示之后 <span ng-bind-html="value.postBody"></span> 并继续显示为html 输出: <p>test post body</p&g
ptest post body/;p
”
首先,我分析纯文本
data[i].postBody = $sce.trustAsHtml(data[i].postBody);
在我这样做并尝试使用ng bind html显示之后
<span ng-bind-html="value.postBody"></span>
并继续显示为html
输出:
<p>test post body</p>
测试柱体
我无法显示没有html标记的文本
请帮帮我 首先使用htmlDecode函数转义HTML实体 HTML:
<div ng-bind-html="value.postBody"></div>
小提琴链接:还是一样的问题:/我以前试过,但没有改变任何东西。这对你有用吗?是的,这对我有用,让我签入fiddle/plunkr,或者共享如果你创建了一个请检查更新的答案,我有一个
ng click
事件关联,所以也使用了compile template
指令,这在你的情况下不是必需的,如果你想要,我也可以在答案中保留这是我的问题,过来看!问题是编译模板没有任何区别
angular.module('ngApp', ['ngSanitize'])
.controller('controller1', ['$scope','$sce', function($scope, $sce) {
// Some Code ...
...
...
function htmlDecode(input) {
var e = document.createElement('div');
e.innerHTML = input;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
data[i].postBody = $sce.trustAsHtml(htmlDecode(data[i].postBody));
...
...
// Some Code ...
}]);