Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Inconsistent ng-if behaviour with strings. #7742

Closed
Elijen opened this issue Jun 8, 2014 · 1 comment
Closed

Inconsistent ng-if behaviour with strings. #7742

Elijen opened this issue Jun 8, 2014 · 1 comment

Comments

@Elijen
Copy link
Contributor

Elijen commented Jun 8, 2014

For some reason, when ng-if directive receives string '0' the statement is evaluated as false. I am not sure if this is a bug or a feature, but I believe it's wrong behaviour because it makes ng-if behave inconsistent. See the following plunker:

http://plnkr.co/edit/GSwxpOyJvCkM66KqqDct

  • Any string evaluates to true, it's negation evaluates to false.
  • Integer 0 evaluates to false, it's negation evaluates to true.
  • Integer 1 evaluates to true, it's negation evaluates to false.

This is how JavaScript works and I would expect Angular to behave the same way, but in angular template the following is also true:

  • String '0' evaluates to false, it's negation evaluates also to false.

Expected behaviour:

  • String '0' evaluates to true, it's negation evaluates to false.

If this is really a feature, shouldn't at least the negation evaluate to the opposite value?

@lgalfaso
Copy link
Contributor

Hi, this issue is a duplicate of #3969 and many other. There is a PR at #4005 that solves this

@lgalfaso lgalfaso removed their assignment Jun 13, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants