mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
fix(booleanAttrs): convert to boolean
jQuery's attr() does not handle 0 as false, when it comes to boolean attrs.
This commit is contained in:
parent
21b77ad5c2
commit
dcb8e0767f
2 changed files with 13 additions and 1 deletions
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue