angularjs - How can I catch ngSantitize errors and display the html as escaped text -
we using angularjs try , display user entered content html. of time users enter valid/safe data display correctly using ng-bind-html. enter invalid html still display raw text.
if use ng-bind-html attempt display invalid html error:
[$sanitize:badparse] sanitizer unable parse following block of html:
i don't want use trustashtml because don't trust our sanitizer , want ensure not display unsafe html on page.
according ngbindhtmldirective
can this:
html:
<div ng-if="issafehtml()"> <div ng-bind-html="invalidhtml"></div> </div> <div ng-if="!issafehtml()"> {{invalidhtml}} </div>
js:
$scope.issafehtml = function() { return !!$sce.gettrustedhtml($scope.invalidhtml); }
modified plunkr: http://plnkr.co/edit/besix3pfq1tjueeagfca?p=preview
Comments
Post a Comment