Jump to content

Custom filters


Mad_Griffith

Recommended Posts

Hello, I am learning Angular and I am trying to create a more complex filter that replaces BBCode with the html tags, which works like this:

 

{{app.text|BBCode}}

With no parameter, show the text with the BBCode converted to HTML tags.

 

{{app.otherText|BBCode:remove}}

If parameter "remove" is specified, then actually strip BBCode from text.

 

I use both at the same time in my html.

 

This is the simple code, but it doesn't work: the first IF is skipped. When I log 'isRemoved' it shows up as 'undefined' for all the occurrences of the expressions, including those with the 'remove' parameter specified.

			portfolio.filter('BBCode', function() {
				return function(input, isRemoved) {
					input = input || '';
					var output;
					if (angular.isDefined(isRemoved) && angular.equals(isRemoved, 'remove')) {
						output = input.replace(/\[(.*?)\]/g, '');
					} else {
						output = input.replace(/\[(.*?)\]/g, '<$1>');
					}
					return output;						
				};
			});

Thank you for your help!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...