Angularjs ng-bind-html-unsafe replacement

后端 未结 4 1335
梦毁少年i
梦毁少年i 2020-12-09 12:50

I used to be able to use ng-bind-html-unsafe to output unsanitized code (because sanitization happens serverside).

But now that option is gone? I know I

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 13:28

    Simplest way, without $sce:

    module.directive('html', function() {
        function link(scope, element, attrs) {
    
            var update = function() {
                element.html(scope.html);
            }
    
            attrs.$observe('html', function(value) {
                update();
            });
        }
    
        return {
            link: link,
            scope:  {
                html:   '='
            }
        };
    });
    

    How to use:

提交回复
热议问题