【发布时间】:2016-02-22 12:38:05
【问题描述】:
我正在从第 3 方获取 json 数据。其中一些使用 ng-bind 渲染正常,它在其中转换和渲染 html 代码。
但对于其他人则不然。好像需要再次ng-bind。
我尝试通过函数或过滤器运行它
$scope.trustedHtml = function (plainText) {
return $sce.trustAsHtml(plainText);
}
ng-bind-html="trustedHtml(hotelDetails.roomInformation)"
我还在我的应用中尝试了过滤器
.filter("to_trusted", ['$sce', function($sce) {
return function(htmlCode){
return $sce.trustAsHtml(htmlCode);
}
}]);
但是这两个都不起作用(如果我做错了什么)。如何让 html 在我的页面上正确呈现?
这就是我从 API 中得到的结果
<p><b>Know Before You Go</b> <br /><ul> <li>
这就是我使用 ng-bing-html 得到的结果,与通过函数运行它相同
<p><b>Know Before You Go</b> <br /><ul> <li>
【问题讨论】:
-
你能用你收到的数据示例创建一个 JSFiddle 吗?
标签: angularjs