angular-sanitize-custom

1.3.1 • Public • Published

angular-sanitize-custom

(Based on angular-sanitize v1.6.9)

Add method `addValidElements` back to the old version(<1.6.10) of angular-sanitize.


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

  1. Install to your project as dependency from NPM (https://www.npmjs.com/package/angular-sanitize-custom)
npm install angular-sanitize-custom --save
  1. Load the dependency
<script src="/node_modules/angular-sanitize-custom/angular-sanitize-custom.min.js"></script>
  1. Define the dependency to your Angular module
angular.module('myApp', ['ngSanitize']);
  1. 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

Package Sidebar

Install

npm i angular-sanitize-custom

Weekly Downloads

2

Version

1.3.1

License

MIT

Unpacked Size

47.9 kB

Total Files

10

Last publish

Collaborators

  • ssmak