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

fix($compile): handle boolean attributes in @ bindings #13769

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2969,10 +2969,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
}
});
attrs.$$observers[attrName].$$scope = scope;
if (isString(attrs[attrName])) {
lastValue = attrs[attrName];
if (isString(lastValue)) {
// If the attribute has been provided then we trigger an interpolation to ensure
// the value is there for use in the link fn
destination[scopeName] = $interpolate(attrs[attrName])(scope);
destination[scopeName] = $interpolate(lastValue)(scope);
} else if (isBoolean(lastValue)) {
// If the attributes is one of the BOOLEAN_ATTR then Angular will have converted
// the value to boolean rather than a string, so we special case this situation
destination[scopeName] = lastValue;
}
break;

Expand Down
18 changes: 18 additions & 0 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2694,6 +2694,24 @@ describe('$compile', function() {
expect(element.isolateScope()['watch']).toBe('watch');
})
);

it('should handle @ bindings on BOOLEAN attributes', function() {
var checkedVal;
module(function($compileProvider) {
$compileProvider.directive('test', function() {
return {
scope: { checked: '@' },
link: function(scope, element, attrs) {
checkedVal = scope.checked;
}
};
});
});
inject(function($compile, $rootScope) {
$compile('<input test checked="checked">')($rootScope);
expect(checkedVal).toEqual(true);
});
});
});


Expand Down