angular输出html

2017-10-23  本文已影响62人  老男人一枚的博客

通过指令 ng-bind-html来实现html的输出

<div class="col-md-12 ng-binding" ng-bind-html="item.content ">  

还需要通过通过$sce服务来实现html的展示

angular.module("list",[]).controller("BlogListCtrl", BlogListCtrl).filter(  
    'to_trusted', ['$sce', function ($sce) {  
        return function (text) {  
            return $sce.trustAsHtml(text);  
        }  
    }]  
)  

这里通过$sce构建一个过滤器来对输出的html进行过滤

<div class="col-md-12 ng-binding" ng-bind-html="item.content|to_trusted ">   
上一篇 下一篇

猜你喜欢

热点阅读