forked from angular/angular.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): drop the toBoolean function
So far Angular have used the toBoolean function to decide if the parsed value is truthy. The function made more values falsy than regular JavaScript would, e.g. strings 'f' and 'no' were both treated as falsy. This creates suble bugs when backend sends a non-empty string with one of these values and something suddenly hides in the application BREAKING CHANGE: values 'f', '0', 'false', 'no', 'n', '[]' are no longer treated as falsy. Only JavaScript falsy values are now treated as falsy by the expression parser; there are six of them: false, null, undefined, NaN, 0 and "". Fixes angular#3969 Fixes angular#4277
- Loading branch information
Showing
8 changed files
with
29 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,10 @@ | |
* <div ng-show="myValue" class="ng-hide"></div> | ||
* ``` | ||
* | ||
* When the ngShow expression evaluates to false then the ng-hide CSS class is added to the class attribute | ||
* on the element causing it to become hidden. When true, the ng-hide CSS class is removed | ||
* When the ngShow expression evaluates to a falsy value then the ng-hide CSS class is added to the class | ||
* attribute on the element causing it to become hidden. When true, the ng-hide CSS class is removed | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mgol
Author
Owner
|
||
* from the element causing the element not to appear hidden. | ||
* | ||
* <div class="alert alert-warning"> | ||
* **Note:** Here is a list of values that ngShow will consider as a falsy value (case insensitive):<br /> | ||
* "f" / "0" / "false" / "no" / "n" / "[]" | ||
* </div> | ||
* | ||
* ## Why is !important used? | ||
* | ||
* You may be wondering why !important is used for the .ng-hide CSS class. This is because the `.ng-hide` selector | ||
|
@@ -163,7 +158,7 @@ | |
var ngShowDirective = ['$animate', function($animate) { | ||
return function(scope, element, attr) { | ||
scope.$watch(attr.ngShow, function ngShowWatchAction(value){ | ||
$animate[toBoolean(value) ? 'removeClass' : 'addClass'](element, 'ng-hide'); | ||
$animate[!!value ? 'removeClass' : 'addClass'](element, 'ng-hide'); | ||
}); | ||
}; | ||
}]; | ||
|
@@ -188,15 +183,10 @@ var ngShowDirective = ['$animate', function($animate) { | |
* <div ng-hide="myValue"></div> | ||
* ``` | ||
* | ||
* When the ngHide expression evaluates to true then the .ng-hide CSS class is added to the class attribute | ||
* on the element causing it to become hidden. When false, the ng-hide CSS class is removed | ||
* When the ngHide expression evaluates to a truthy value then the .ng-hide CSS class is added to the class | ||
* attribute on the element causing it to become hidden. When false, the ng-hide CSS class is removed | ||
This comment has been minimized.
Sorry, something went wrong. |
||
* from the element causing the element not to appear hidden. | ||
* | ||
* <div class="alert alert-warning"> | ||
* **Note:** Here is a list of values that ngHide will consider as a falsy value (case insensitive):<br /> | ||
* "f" / "0" / "false" / "no" / "n" / "[]" | ||
* </div> | ||
* | ||
* ## Why is !important used? | ||
* | ||
* You may be wondering why !important is used for the .ng-hide CSS class. This is because the `.ng-hide` selector | ||
|
@@ -319,7 +309,7 @@ var ngShowDirective = ['$animate', function($animate) { | |
var ngHideDirective = ['$animate', function($animate) { | ||
return function(scope, element, attr) { | ||
scope.$watch(attr.ngHide, function ngHideWatchAction(value){ | ||
$animate[toBoolean(value) ? 'addClass' : 'removeClass'](element, 'ng-hide'); | ||
$animate[!!value ? 'addClass' : 'removeClass'](element, 'ng-hide'); | ||
}); | ||
}; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The previous sentence reads
When ... falsy .. then...
to be consistent this sentence should beWhen truthy, ...