top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to securely parse and manipulate your HTML data in AngularJS?

0 votes
361 views
How to securely parse and manipulate your HTML data in AngularJS?
posted Dec 1, 2017 by Jayshree

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

AngularJS provides ngSanitize module to securely parse and manipulate HTML data in your application.
To use it include the angular-sanitize.js file and set ngSanitize as a dependency in your angular app.

var app = angular.module('sanitizeExample', ['ngSanitize']);
app.controller('ExampleController',function ($scope, $sce) {
 var snippet ='<p style="color:blue">an html\n' +
 '<em onmouseover="this.textContent=\'PWN3D!\'">click here</em>\n snippet</p>';
 $scope.trustedSnippet = $sce.trustAsHtml(snippet); //sce=Strict Contextual Escaping
});

The snippet may contain HTML, CSS, URLs and JavaScript code which you want to safely render in your app.

answer Dec 1, 2017 by Shivaranjini
...