How do you use $sce.trustAsHtml(string) to replicate ng-bind-html-unsafe in Angular 1.2+

前端 未结 10 1609
别跟我提以往
别跟我提以往 2020-11-22 03:51

ng-bind-html-unsafe was removed in Angular 1.2

I\'m trying to implement something where I need to use ng-bind-html-unsafe. In the docs and

10条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 04:15

    That should be:

    plus in your controller:

    $scope.html = '
    • render me please
    '; $scope.trustedHtml = $sce.trustAsHtml($scope.html);

    instead of old syntax, where you could reference $scope.html variable directly:

    As several commenters pointed out, $sce has to be injected in the controller, otherwise you will get $sce undefined error.

     var myApp = angular.module('myApp',[]);
    
     myApp.controller('MyController', ['$sce', function($sce) {
        // ... [your code]
     }]);
    

提交回复
热议问题