How to Strip HTML Tags in AngularJS

Here’s a reusable code snippet which allows you to remove HTML tags from text using a simple AngularJS filter.

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

app.filter('stripTags', function() {
	return function(text) {
		return  text ? String(text).replace(/<[^>]+>/gm, '') : '';
	};
});

Usage:

<p>{{ someRandomText | stripTags }}</p>  

Read Also: Capitalize The First Letter of String Using AngularJS

Source: http://stackoverflow.com/a/17315483

Leave a Comment.