aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojta Jina2012-04-04 08:12:39 -0700
committerVojta Jina2012-04-04 08:26:28 -0700
commitdcb8e0767fbf0a7a55f3b0045fd01b2532ea5441 (patch)
tree3726eac589962daf7036889cc5722310096d949d
parent21b77ad5c231ab0e05eb89f22005f7ed8d40a6c1 (diff)
downloadangular.js-dcb8e0767fbf0a7a55f3b0045fd01b2532ea5441.tar.bz2
fix(booleanAttrs): convert to boolean
jQuery's attr() does not handle 0 as false, when it comes to boolean attrs.
-rw-r--r--src/ng/directive/booleanAttrDirs.js2
-rw-r--r--test/ng/directive/booleanAttrDirSpecs.js12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/ng/directive/booleanAttrDirs.js b/src/ng/directive/booleanAttrDirs.js
index 01134998..fee10ed8 100644
--- a/src/ng/directive/booleanAttrDirs.js
+++ b/src/ng/directive/booleanAttrDirs.js
@@ -288,7 +288,7 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
return function(scope, element, attr) {
attr.$$observers[attrName] = [];
scope.$watch(attr[normalized], function(value) {
- attr.$set(attrName, value);
+ attr.$set(attrName, !!value);
});
};
}
diff --git a/test/ng/directive/booleanAttrDirSpecs.js b/test/ng/directive/booleanAttrDirSpecs.js
index aa84c1ae..d58ffced 100644
--- a/test/ng/directive/booleanAttrDirSpecs.js
+++ b/test/ng/directive/booleanAttrDirSpecs.js
@@ -23,6 +23,18 @@ describe('boolean attr directives', function() {
}));
+ it('should properly evaluate 0 as false', inject(function($rootScope, $compile) {
+ // jQuery does not treat 0 as false, when setting attr()
+ element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
+ $rootScope.isDisabled = 0;
+ $rootScope.$digest();
+ expect(element.attr('disabled')).toBeFalsy();
+ $rootScope.isDisabled = 1;
+ $rootScope.$digest();
+ expect(element.attr('disabled')).toBeTruthy();
+ }));
+
+
it('should bind disabled', inject(function($rootScope, $compile) {
element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
$rootScope.isDisabled = false;