search

Home  >  Q&A  >  body text

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

$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 class="u-formatedText" ng-bind-html="page.content"></p>

我在Content里面写已经写好的指令,然后输出结果是只有一个标签,里面没有内容

世界只因有你世界只因有你2744 days ago567

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-15 16:57:07

    Insert the entire HTML使用的是ng-include而不是ng-bind或者ng-bind-template;我这里写的有一个例子,你可以看看,demo。当然你也可以使用$templateCacheservice to achieve your desired results.


    It was wrong at first glance. It turned out to be the ng-bind-html,我还以为是ng-bind-template,使用ng-bind-html之前,要引入ngSanitize module, otherwise an error would have been reported. The official example is here ngBindHtml, you can take a look.

    reply
    0
  • Cancelreply