From 1b541500ab17d362998e5824771aad300017c8d9 Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Thu, 2 Jan 2014 14:48:03 -0800 Subject: [PATCH] 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 --- src/Angular.js | 4 +++- test/ng/directive/ngShowHideSpec.js | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Angular.js b/src/Angular.js index 386682a325e7..11ce5cf5be1a 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -959,7 +959,9 @@ function fromJson(json) { function toBoolean(value) { - if (value && value.length !== 0) { + if (typeof value === 'function') { + value = true; + } else if (value && value.length !== 0) { var v = lowercase("" + value); value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]'); } else { diff --git a/test/ng/directive/ngShowHideSpec.js b/test/ng/directive/ngShowHideSpec.js index 4a8e55da386e..ee83c31b65a9 100644 --- a/test/ng/directive/ngShowHideSpec.js +++ b/test/ng/directive/ngShowHideSpec.js @@ -20,6 +20,16 @@ describe('ngShow / ngHide', function() { })); + // https://github.com/angular/angular.js/issues/5414 + it('should show if the expression is a function with a single argument', inject(function($rootScope, $compile) { + element = jqLite('
'); + element = $compile(element)($rootScope); + $rootScope.exp = function(){}; + $rootScope.$digest(); + expect(element).toBeShown(); + })); + + it('should make hidden element visible', inject(function($rootScope, $compile) { element = jqLite('
'); element = $compile(element)($rootScope);