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

Commit 01c5be4

Browse files
committed
fix(ngShow/ngHide, ngIf): functions with zero args should be truthy
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 #5414
1 parent fd9a03e commit 01c5be4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Angular.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,9 @@ function fromJson(json) {
959959

960960

961961
function toBoolean(value) {
962-
if (value && value.length !== 0) {
962+
if (typeof value === 'function') {
963+
value = true;
964+
} else if (value && value.length !== 0) {
963965
var v = lowercase("" + value);
964966
value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
965967
} else {

test/ng/directive/ngShowHideSpec.js

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ describe('ngShow / ngHide', function() {
2020
}));
2121

2222

23+
// https://github.com/angular/angular.js/issues/5414
24+
it('should show if the expression is a function with a no arguments', inject(function($rootScope, $compile) {
25+
element = jqLite('<div ng-show="exp"></div>');
26+
element = $compile(element)($rootScope);
27+
$rootScope.exp = function(){};
28+
$rootScope.$digest();
29+
expect(element).toBeShown();
30+
}));
31+
32+
2333
it('should make hidden element visible', inject(function($rootScope, $compile) {
2434
element = jqLite('<div class="ng-hide" ng-show="exp"></div>');
2535
element = $compile(element)($rootScope);

0 commit comments

Comments
 (0)