
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
angular-sanitize
Advanced tools
The angular-sanitize package is an AngularJS module that provides functionality to sanitize HTML content. It helps in preventing cross-site scripting (XSS) attacks by cleaning up the HTML content before it is displayed in the application.
Sanitize HTML Content
This feature allows you to sanitize HTML content to prevent XSS attacks. The code sample demonstrates how to use the $sce service to trust HTML content and bind it to the scope.
angular.module('myApp', ['ngSanitize'])
.controller('myController', ['$scope', '$sce', function($scope, $sce) {
$scope.htmlContent = $sce.trustAsHtml('<p style="color:blue">Hello World</p>');
}]);
Bind HTML Content to View
This feature allows you to bind sanitized HTML content to the view using the ng-bind-html directive. The code sample shows how to bind the trusted HTML content to a div element.
<div ng-app="myApp" ng-controller="myController">
<div ng-bind-html="htmlContent"></div>
</div>
DOMPurify is a DOM-only, super-fast, uber-tolerant XSS sanitizer for HTML, MathML, and SVG. It is similar to angular-sanitize in that it provides functionality to sanitize HTML content, but it is not specific to AngularJS and can be used in any JavaScript environment.
sanitize-html provides a simple HTML sanitizer with a clear API. It allows you to define a whitelist of allowed tags and attributes, making it highly customizable. Unlike angular-sanitize, it is not tied to AngularJS and can be used in any JavaScript application.
xss is a module that filters input from users to prevent XSS attacks. It provides a rich set of options to customize the sanitization process. Similar to angular-sanitize, it focuses on preventing XSS attacks but is not limited to AngularJS applications.
This package contains the legacy AngularJS (version 1.x). AngularJS support has officially ended as of January 2022. See what ending support means and read the end of life announcement.
See @angular/core
for the actively supported Angular.
You can install this package either with npm
or with bower
.
npm install angular-sanitize
Then add ngSanitize
as a dependency for your app:
angular.module('myApp', [require('angular-sanitize')]);
bower install angular-sanitize
Add a <script>
to your index.html
:
<script src="/bower_components/angular-sanitize/angular-sanitize.js"></script>
Then add ngSanitize
as a dependency for your app:
angular.module('myApp', ['ngSanitize']);
Documentation is available on the AngularJS docs site.
The MIT License
Copyright (c) 2022 Google LLC
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
AngularJS module for sanitizing HTML
The npm package angular-sanitize receives a total of 178,286 weekly downloads. As such, angular-sanitize popularity was classified as popular.
We found that angular-sanitize demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.