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

前端 未结 10 1645
别跟我提以往
别跟我提以往 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:20

    If you want the old directive back, you can add this to your app:

    Directive:

    directives.directive('ngBindHtmlUnsafe', ['$sce', function($sce){
        return {
            scope: {
                ngBindHtmlUnsafe: '=',
            },
            template: "
    ", link: function($scope, iElm, iAttrs, controller) { $scope.updateView = function() { $scope.trustedHtml = $sce.trustAsHtml($scope.ngBindHtmlUnsafe); } $scope.$watch('ngBindHtmlUnsafe', function(newVal, oldVal) { $scope.updateView(newVal); }); } }; }]);

    Usage

    Source - https://github.com/angular-ui/bootstrap/issues/813

提交回复
热议问题