Skip to content

方法一使用ngSanitize

angular.module('app').filter('unsafe', function($sce) { return sce的$sce.trustAsHtml 取代, 但是我们也可以通过使用指令的方式达到相同的目的

方法二自定指令

不用ngSanitize

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: