ngSanitize:badparse for <style> <! - \ n - > </style>给出了错误的解析错误angularjs

时间:2017-09-20 05:41:13

标签: angularjs ngsanitize

我在尝试清理时遇到了一个错误的错误

<style> <!--\n--> </style>给出了错误的解析错误angularjs。我在我的模块中使用ngSanitize进行清理。我能够很好地解析大多数HTML内容,但这失败了。

这个字符串失败有特殊原因吗?

TIA

1 个答案:

答案 0 :(得分:0)

&#13;
&#13;
angular.module('app', ['ngSanitize'])
.controller('ctrl', ['$scope', '$sce', function($scope, $sce) {     
    $scope.style = $sce.trustAsHtml(
   `<script>
      alert("Some bad");
    <\/script>
    <style>
        .green{
            background-color:green
        }
    </style>`);      
}])
&#13;
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular-sanitize.min.js"></script>

<div ng-app='app' ng-controller="ctrl">
    <div ng-bind-html='style'></div>
    <div class='green'>Green</div>    
</div>
&#13;
&#13;
&#13;