Filter for insert HTML in Angular Js

filter
show html
angular js
html

If you need to display raw HTML content to the page view with AngularJS, you can use the $sce service that comes with AngularJS. $sce stands for Strict Contextual Escaping. The service has trustAsHTML method with take some arbitrary text or HTML.

Example HTML content is 

$scope.html = '<b>render me please</b>';

The html code is

<p class="text">{{html}}</p>

from the user side the html will display  as

<b>render me please</b>

By using the below filter, the text will displayed as 

render me please

The filter is 

angular.module('test').filter('RenderHtmlText', function($sce) {
    return function(val) {
		return $sce.trustAsHtml(val);
    };
});

$sce is a service that provides Strict Contextual Escaping services to AngularJS.

You might also like:

Convert and download html to pdf without saving file

28-10-2018 node js convert html to pdf pdf download pdf without saving

Get previous date from given date in javascript

06-03-2017 date javascript previous date

Change datepicker display format

06-03-2017 datepicker angular js

How to change background color and color to the text using javascript

27-02-2017 css javascript colors

Call a function every second or 5 seconds in javascript

22-02-2017 setinterval function calling