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

Commit

Permalink
fix(booleanAttrs): convert to boolean
Browse files Browse the repository at this point in the history
jQuery's attr() does not handle 0 as false, when it comes to boolean attrs.
  • Loading branch information
vojtajina committed Apr 4, 2012
1 parent 21b77ad commit dcb8e07
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ng/directive/booleanAttrDirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
}
Expand Down
12 changes: 12 additions & 0 deletions test/ng/directive/booleanAttrDirSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dcb8e07

Please sign in to comment.