您的位置:首頁技術文章
文章詳情頁

angular.js - angularjs ng-bind-html如何插入整段HTML

瀏覽:131日期:2024-03-19 15:14:38

問題描述

$scope.pages = [{ title: ’信息’, content: ’detailMessage’}, { title: ’集裝箱/車’, content: ’dddd’}, { title: ’貨物’, content: ’eee’}, { title: ’記錄’, content: ’fff’}];

.directive(’detailMessage’, function() {return { restrict: ’EC’, templateUrl: ’views/partials/message.html’, transclude: true, replace: true}; })

<p ng-bind-html='page.content'></p>

我在Content里面寫已經寫好的指令,然后輸出結果是只有一個標簽,里面沒有內容

問題解答

回答1:

插入整段HTML使用的是ng-include而不是ng-bind或者ng-bind-template;我這里寫的有一個例子,你可以看看,demo。當然你也可以使用$templateCache服務來實現你想要的結果。

第一眼看錯了,原來是ng-bind-html,我還以為是ng-bind-template,使用ng-bind-html之前,要引入ngSanitize模塊,不然會報錯的,官方示例在這里ngBindHtml,你可以看看。

標簽: HTML
相關文章:
国产综合久久一区二区三区