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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -