Compiling dynamic HTML strings from database

前端 未结 5 1305
花落未央
花落未央 2020-11-22 02:14

The Situation

Nested within our Angular app is a directive called Page, backed by a controller, which contains a div with an ng-bind-html-unsafe attribute. This is

5条回答
  •  走了就别回头了
    2020-11-22 02:52

    You can use

    ng-bind-html https://docs.angularjs.org/api/ng/service/$sce

    directive to bind html dynamically. However you have to get the data via $sce service.

    Please see the live demo at http://plnkr.co/edit/k4s3Bx

    var app = angular.module('plunker', []);
    app.controller('MainCtrl', function($scope,$sce) {
        $scope.getHtml=function(){
       return $sce.trustAsHtml("Hi Rupesh hi dfdfdfdf!sdafsdfsdf");
       }
    });
    
      
    
      
    

提交回复
热议问题