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

toBoolean has inconsistent results for functions with 0 arguments and for functions with more than 0 arguments #5414

Closed
capaj opened this issue Dec 15, 2013 · 1 comment
Assignees
Milestone

Comments

@capaj
Copy link

capaj commented Dec 15, 2013

I have a plnkr demonstrating the issue here:

http://plnkr.co/edit/MeivE2RRsRFKF3n05vwX?p=preview

To boolean should return consistent results for any function, no matter how many arguments it has.

@ghost ghost assigned vojtajina Dec 21, 2013
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now visible
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Dec 30, 2013
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now visible

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
@ghost ghost assigned btford Dec 30, 2013
@btford
Copy link
Contributor

btford commented Jan 2, 2014

I like the changes suggested by @lgalfaso, but I think they only make sense in a 1.3.x release. To immediately fix the issue for 1.2.x, I think changing the behavior of toBoolean to explicitly make all fns truthy is the right thing to do.

I'm working on a fix here: https://github.com/btford/angular.js/tree/gh-5414

btford added a commit to btford/angular.js that referenced this issue Jan 2, 2014
Previously, expressions that were a function with one or more arguments evaluated to
true, but functions with zero arguments evaluated to false.

Closes angular#5414
btford added a commit to btford/angular.js that referenced this issue Jan 2, 2014
Previously, expressions that were a function with one or more arguments evaluated to
true, but functions with zero arguments evaluated to false.

This behavior seems both unintentional and undesirable. This patch makes a function
truthy regardless of its number of arguments.

Closes angular#5414
@btford btford closed this as completed in 01c5be4 Jan 3, 2014
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Previously, expressions that were a function with one or more arguments evaluated to
true, but functions with zero arguments evaluated to false.

This behavior seems both unintentional and undesirable. This patch makes a function
truthy regardless of its number of arguments.

Closes angular#5414
jamesdaily pushed a commit to jamesdaily/angular.js that referenced this issue Jan 27, 2014
Previously, expressions that were a function with one or more arguments evaluated to
true, but functions with zero arguments evaluated to false.

This behavior seems both unintentional and undesirable. This patch makes a function
truthy regardless of its number of arguments.

Closes angular#5414
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Feb 5, 2014
Make ngShow and ngHide follow javascript `truthy`/`falsy` logic and
not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Feb 5, 2014
Make ngIf, ngShow and ngHide follow javascript `truthy`/`falsy`
logic and not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
lgalfaso added a commit to lgalfaso/angular.js that referenced this issue Jun 5, 2014
Make ngIf, ngShow and ngHide follow javascript `truthy`/`falsy`
logic and not the custom toBoolean logic

Fixes angular#5414 angular#4277 angular#3969

BREAKING CHANGE: The expressions

* `<div ng-hide="[]">X</div>`
* `<div ng-hide="'f'">X</div>`
* `<div ng-hide="'[]'">X</div>`

used to be evaluated to `false` and the elements were hidden.

The same effect is present for `ng-show` and the elements are now
  visible; and with `ng-if` and the elements are now removed

If you were previously doing `ng-show="exp"` where
  `$scope.exp = 'no' // (or 'n' or 'f')`, then instead write
  `ng-show="exp && exp !== 'no'` (or 'n' or 'f').
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.