<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</head>
<body>
<b>Direct Escaping </b><br/>
<div ng-app="demo1" ng-controller="home">
Original Text : {{text}}
<br/>
<br/>EscapedText : <span ng-bind-html="text"></span>
</div>
<br/>
<br/>--------------------------------
<br/> <b>Using Angular Filter</b><br/>
<br/>
<div ng-app="demo2" ng-controller="home">
Original Text : {{text}}
<br/>
<br/>EscapedText : <span ng-bind-html="text | escapeHtml"></span>
</div>
<script src="app.js"></script>
</body>
</html>
var demo1 = angular.module("demo1",[]);
demo1.controller('home', function ($scope, $sce) {
$scope.text = $sce.trustAsHtml("hi this is a <b>demo text</b> <br> <a href='#'>This is a link</a>");
});
var demo2 = angular.module("demo2",[]);
demo2.filter('escapeHtml', function($sce) {
return function(val) {
return $sce.trustAsHtml(val);
};
});
demo2.controller('home', function ($scope, $sce) {
$scope.text = $sce.trustAsHtml("hi this is a <b>demo text</b> <br> <a href='#'>This is a link</a>");
});