Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replaceIfBlank string filter? #56

Closed
mikecarroll opened this issue Nov 29, 2014 · 3 comments
Closed

Add replaceIfBlank string filter? #56

mikecarroll opened this issue Nov 29, 2014 · 3 comments

Comments

@mikecarroll
Copy link

I'm looking for a string filter that replaces a null or empty string with a desired input. For example:

<p>{{ "" | replaceIfBlank:"N/A" }}</p>
<!--result: <p>N/A</p>-->

<h2>{{ null | replaceIfBlank:"Title not given" }}</h2>
<!--result: <n2>Title not given</h2>-->

Happy to build this myself and contribute via a PR, if it sounds useful and isn't already included here or in the native Angular filters (but just being overlooked by me).

@mikecarroll mikecarroll changed the title Add an replaceIfBlank string filter? Add replaceIfBlank string filter? Nov 29, 2014
@a8m
Copy link
Owner

a8m commented Nov 29, 2014

Hi @mikecarroll , what about using the || operator, e.g:

  <p>{{ '' || 'N/A' }}</p>
  <p>{{ null || 'N/A' }}</p>

let me know what do you think..
see: jsbin

@mallowigi
Copy link
Contributor

I agree with @a8m, I think || is simple enough.

@mikecarroll
Copy link
Author

Yeah, very elegant. Embarrassed I didn't think of it in the first place.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants