I'm getting the following data from server <span>text</span>
.
我正在从服务器文本获取以下数据。
I'm using the following function in my controller
我在控制器中使用下面的函数
$scope.getHtml = function (html) {
return $sce.trustAsHtml(html);
};
and in the html as follows
在html中,如下所示
<div class="col-sm-12 col-md-12" ng-bind-html="getHtml(vm.profileData.htmltext)">
After doing this I am getting this in view, it is not rendering :
在这样做之后,我看到了这个,它不是渲染:
<span>text</span>
Please tell me where I'm getting things wrong? Thanks in advance
请告诉我哪里出错了?谢谢提前
2 个解决方案
#1
3
as i mention you need a html entity decode
正如我提到的,您需要一个html实体解码
$scope.html = angular.element('<div></div>').html('<i>text</i>').text();
$scope.getHtml = function() {
return $sce.trustAsHtml($scope.html);
};
砰砰作响的url
#2
0
I recommend this code for this.
我推荐这段代码。
function htmlDecode(str) {
return $('<textarea />').html(str).text();
}
// angular js
$sce.trustAsHtml(htmlDecode(html));
#1
3
as i mention you need a html entity decode
正如我提到的,您需要一个html实体解码
$scope.html = angular.element('<div></div>').html('<i>text</i>').text();
$scope.getHtml = function() {
return $sce.trustAsHtml($scope.html);
};
砰砰作响的url
#2
0
I recommend this code for this.
我推荐这段代码。
function htmlDecode(str) {
return $('<textarea />').html(str).text();
}
// angular js
$sce.trustAsHtml(htmlDecode(html));