但是這裏我們需要其顯示angular輸出的html能被瀏覽器解析怎麽辦呢?
通過api,發現通過指令 ng-bind-html來實現html的輸出。
[html] view plain copy 在CODE上查看代碼片派生到我的代碼片
<div class="col-md-12 ng-binding" ng-bind-html="item.content ">
但是並不起作用,瀏覽器中顯示的還是html代碼。
‘後來發現還需要通過通過$sce服務來實現html的展示。
[html] view plain copy 在CODE上查看代碼片派生到我的代碼片
angular.module("list",[]).controller("BlogListCtrl", BlogListCtrl).filter(
'to_trusted', ['$sce', function ($sce) {
return function (text) {
return $sce.trustAsHtml(text);
}
}]
)
這裏通過$sce構建壹個過濾器來對輸出的html進行過濾
[html] view plain copy 在CODE上查看代碼片派生到我的代碼片
<div class="col-md-12 ng-binding" ng-bind-html="item.content|to_trusted ">
這樣就可以通過angularjs正常的輸出html標簽,並且被瀏覽器解析了