diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index e132f13b02eb..268e2bbecc66 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -85,9 +85,9 @@ var ngIfDirective = ['$animate', function($animate) { $$tlb: true, link: function ($scope, $element, $attr, ctrl, $transclude) { var block, childScope; - $scope.$watch($attr.ngIf, function ngIfWatchAction(value) { + $scope.$watch('!!(' + $attr.ngIf + ')', function ngIfWatchAction(value) { - if (toBoolean(value)) { + if (value) { if (!childScope) { childScope = $scope.$new(); $transclude(childScope, function (clone) { diff --git a/src/ng/directive/ngShowHide.js b/src/ng/directive/ngShowHide.js index ba33bb1a69de..eab90b70a6c9 100644 --- a/src/ng/directive/ngShowHide.js +++ b/src/ng/directive/ngShowHide.js @@ -150,8 +150,8 @@ */ 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'); + scope.$watch('!!(' + attr.ngShow + ')', function ngShowWatchAction(value){ + $animate[value ? 'removeClass' : 'addClass'](element, 'ng-hide'); }); }; }]; @@ -307,8 +307,8 @@ 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'); + scope.$watch('!!(' + attr.ngHide + ')', function ngHideWatchAction(value){ + $animate[value ? 'addClass' : 'removeClass'](element, 'ng-hide'); }); }; }]; diff --git a/test/BinderSpec.js b/test/BinderSpec.js index b553c68dcfd0..8f1a9da1abc4 100644 --- a/test/BinderSpec.js +++ b/test/BinderSpec.js @@ -272,7 +272,7 @@ describe('Binder', function() { $rootScope.hidden = 'false'; $rootScope.$apply(); - assertVisible(element); + assertHidden(element); $rootScope.hidden = ''; $rootScope.$apply(); @@ -291,7 +291,7 @@ describe('Binder', function() { $rootScope.show = 'false'; $rootScope.$apply(); - assertHidden(element); + assertVisible(element); $rootScope.show = ''; $rootScope.$apply(); diff --git a/test/ng/directive/ngIfSpec.js b/test/ng/directive/ngIfSpec.js index db923150502b..73f90a93e225 100755 --- a/test/ng/directive/ngIfSpec.js +++ b/test/ng/directive/ngIfSpec.js @@ -136,6 +136,18 @@ describe('ngIf', function () { expect(element.text()).toBe('before;after;'); }); + it('should evaluate using javascript `truthy`/`falsy` logic', function () { + var cases = ['[]', 'f', [], [''], 'false', {}, function() {}, function(f) {}, 0, false, null, undefined, '', NaN]; + element.append($compile( + '