angular-sanitize-custom
v1.3.1
Published
Add method `addValidElements` back to the old version(<1.6.10) of angular-sanitize.
Downloads
20
Maintainers
Readme
History
I worked on a project that uses Angular version 1.6.9. In order to use ng-bind-html
with custom tag without any errors, we must add all custom tags to the trust list. This method ONLY exists in angular-sanitize v1.6.10 or above, but NOT in v1.6.9 or below.
Follow the requirements of my project, I can't upgrade any libraries and so I need to hack the original version and make it works on the custom tags.
Demonstration on CodePen
https://codepen.io/ssmak/pen/XYmEMO
Installation + Use
- Install to your project as dependency from NPM (https://www.npmjs.com/package/angular-sanitize-custom)
npm install angular-sanitize-custom --save
- Load the dependency
<script src="/node_modules/angular-sanitize-custom/angular-sanitize-custom.min.js"></script>
- Define the dependency to your Angular module
angular.module('myApp', ['ngSanitize']);
- Configure the provider and add any custom tags to the trust list
angular.module('myApp').config($sanitizeProvider => {
$sanitizeProvider.addValidElements(['newElement1', 'newElement2']);
});
Test
A demo page is located in the /test folder. You can test with each version of angular-sanitize with the live reload by using lite-server which can be installed by
npm install lite-server -g
cd /project_root && lite-server
License
MIT