AngularJS - how to remove html tags using filter?

By Hardik Savani | April 12, 2016 | | 76727 Viewer | Category : jQuery AngularJS


Whenever you require to strip HTML tags usign Angular Filter, then this post can help you. If you are working on php then it is very easily use predefine function But in AngularJS you need to make your own filter for remove html tag from string. So, In bellow example you can see how to create and use it.

Create Filter:

var app = angular.module('myHDApp', []);

app.filter('removeHTMLTags', function() {

return function(text) {

return text ? String(text).replace(/<[^>]+>/gm, '') : '';

};

});

Use Filter:

<p>{{ yourText | removeHTMLTags }}</p>



Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
***Do you want me hire for your Project Work? Then Contact US.