Jump to content

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...