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

Commit dcb8e07

Browse files
committed
fix(booleanAttrs): convert to boolean
jQuery's attr() does not handle 0 as false, when it comes to boolean attrs.
1 parent 21b77ad commit dcb8e07

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/ng/directive/booleanAttrDirs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ forEach(BOOLEAN_ATTR, function(propName, attrName) {
288288
return function(scope, element, attr) {
289289
attr.$$observers[attrName] = [];
290290
scope.$watch(attr[normalized], function(value) {
291-
attr.$set(attrName, value);
291+
attr.$set(attrName, !!value);
292292
});
293293
};
294294
}

test/ng/directive/booleanAttrDirSpecs.js

+12
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ describe('boolean attr directives', function() {
2323
}));
2424

2525

26+
it('should properly evaluate 0 as false', inject(function($rootScope, $compile) {
27+
// jQuery does not treat 0 as false, when setting attr()
28+
element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
29+
$rootScope.isDisabled = 0;
30+
$rootScope.$digest();
31+
expect(element.attr('disabled')).toBeFalsy();
32+
$rootScope.isDisabled = 1;
33+
$rootScope.$digest();
34+
expect(element.attr('disabled')).toBeTruthy();
35+
}));
36+
37+
2638
it('should bind disabled', inject(function($rootScope, $compile) {
2739
element = $compile('<button ng-disabled="isDisabled">Button</button>')($rootScope)
2840
$rootScope.isDisabled = false;

0 commit comments

Comments
 (0)