$sanitize和$sce服务的使用方法

var app =angular.module(‘myApp‘,[‘ngSanitize‘]);
app.controller(‘ctrl‘,function($scope,$sce){
    $scope.myHtml = ‘<p >an html
‘ +
    ‘<em onclick="this.textContent=‘code_bunny‘">click here</em>
‘ +
    ‘snippet</p>‘;
    $scope.trustHtml = $sce.trustAsHtml($scope.myHtml)
}

$sanitize会把标签的属性都移除,以及绑定在元素上的事件.仅保留了标签和内容


原文地址:https://www.cnblogs.com/toward-the-sun/p/4288306.html