您可以创建过滤器来清理您的html.
angular.module('filters', []).factory('truncate', function () {
return function strip_tags(input, allowed) {
allowed = (((allowed || '') + '')
.toLowerCase()
.match(//g) || [])
.join(''); // making sure the allowed arg is a string containing only tags in lowercase ()
var tags = /]*>/gi,
commentsAndPhpTags = /|/gi;
return input.replace(commentsAndPhpTags, '')
.replace(tags, function($0, $1) {
return allowed.indexOf('') > -1 ? $0 : '';
});
}
});
控制器:
angular.module('myApp', ['filters'])
.controller('IndexController', ['$scope', 'truncate', '$sce', function($scope, truncate, $sce){
$scope.text="";
$scope.$watch('text', function(){
$scope.sanitized = $sce.trustAsHtml(truncate($scope.text, '
'));
});
}]);
视图: