【发布时间】:2016-05-18 01:24:51
【问题描述】:
我正在从 JSON 中检索数据并检索一些文本内容,但文本内容不支持 p 标签。我将向您展示屏幕截图以获取提示。
当我们检索到文本内容时,它会像这样显示(带有 p 标签)。 JSON 网址:
http://www.json-generator.com/api/json/get/bTRWzhCvuG?indent=2
HTML:
<div ng-controller="chooseProductDescription">
<div ng-repeat="cat in productDescription">
<div>{{cat.product.fullDescription}} </div>
</div>
</div>
控制器:
.controller('chooseProductDescription', function($scope, $http){
$http({
method:'get',
url:'http://www.json-generator.com/api/json/get/bTRWzhCvuG?indent=2',
header:{'Content-Type':'application/json'},
}).success(function(data,status,headers, config){
$scope.productDescription = data;
}).error(function(data, status,headers, config){
})
})
在查看页面中检索内容时,角度 js 中不支持 p 标签。我该怎么办?请告诉我。提前致谢。
【问题讨论】:
-
我会假设
cat.product.fullDescription不会将fullDescription数据输出为原始html,而是将其视为浏览器输出,例如对html 进行编码。 -
尝试在您的
success$scope.productDescription = $sce.trustAsHtml(data)中像这样使用$sce -
@Sachin。这是行不通的。多解释一下?
-
您是否尝试实现
ngBindHtml?正如答案中所建议的那样? -
@Saching。是的,但我没有安装 sanitize。 ngBindHtml 可以在没有消毒的情况下工作吗?
标签: javascript html angularjs json ajax