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.
https://codepen.io/ssmak/pen/XYmEMO
- 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']);
});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-serverMIT