I'm trying to display the html content which I receive in my div.testData by using ng-bind-html together with filter. I've already included 'ngSanitize' in my app. But somehow, it works only partially. Seem like, filter is not getting applied. It works fine when I create a local file and check, but doesn't work when I use the same code in my project environment.
Sample data:
$scope.userProfile.Information = '<p>Hello, this is sample data to test html.</p>';
The output displayed is:
'<p>Hello, this is sample data to test html.</p>'
Desired output is :
'Hello, this is sample data to test html.'
Please help me fix this.
HTML:
<div ng-app="myApp" ng-controller="myCtrl">
<div class="testData" ng-bind-html= "userProfile.Information | to_trusted"></div>
Filter:
app.filter('to_trusted', ['$sce', function($sce){
return function(text) {
var doc = new DOMParser().parseFromString(text, "text/html");
var rval= doc.documentElement.textContent;
//console.log(rval);
return $sce.trustAsHtml(rval);
};
}]);
Answer is here already.