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

Inconsistent return value for shortFmt #205

Open
briandamaged opened this issue Jun 22, 2016 · 0 comments
Open

Inconsistent return value for shortFmt #205

briandamaged opened this issue Jun 22, 2016 · 0 comments

Comments

@briandamaged
Copy link

briandamaged commented Jun 22, 2016

The current behavior

When given an Number less than 1000, shortFmt returns a Number. Otherwise, it returns a String.

Why is this a problem?

Consider the following case:

<span>{{ (n | shortFmt:1) || 'N/A'}}</span>

When n = 0, this will print "N/A" (Why? Because 0 is a false-y value in JS. Therefore, it evaluates the right-hand side of the "||"). I believe that most developers would expect this to print "0" instead. (Similar to the behavior of angular's number filter)

Proposed fix

When n < 1000, return n + ''. This will coerce the Number into a String.

If this seems like a reasonable behavior, then I'll go ahead and create a PR for this later today.

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

No branches or pull requests

1 participant