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

fix(ngShow/ngHide, ngIf): functions with zero args should be truthy #5605

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions test/ng/directive/ngShowHideSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the significance of "single argument"? I don't see it used in the actual test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! should be "zero arguments."

element = jqLite('<div ng-show="exp"></div>');
element = $compile(element)($rootScope);
$rootScope.exp = function(){};
$rootScope.$digest();
expect(element).toBeShown();
}));


it('should make hidden element visible', inject(function($rootScope, $compile) {
element = jqLite('<div class="ng-hide" ng-show="exp"></div>');
element = $compile(element)($rootScope);
Expand Down