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

Commit 2ffbfb0

Browse files
fix($compile): handle boolean attributes in @ bindings
Closes #13767 Closes #13769
1 parent 946d9ae commit 2ffbfb0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ng/compile.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -2631,10 +2631,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26312631
}
26322632
});
26332633
attrs.$$observers[attrName].$$scope = scope;
2634-
if (isString(attrs[attrName])) {
2634+
lastValue = attrs[attrName];
2635+
if (isString(lastValue)) {
26352636
// If the attribute has been provided then we trigger an interpolation to ensure
26362637
// the value is there for use in the link fn
2637-
destination[scopeName] = $interpolate(attrs[attrName])(scope);
2638+
destination[scopeName] = $interpolate(lastValue)(scope);
2639+
} else if (isBoolean(lastValue)) {
2640+
// If the attributes is one of the BOOLEAN_ATTR then Angular will have converted
2641+
// the value to boolean rather than a string, so we special case this situation
2642+
destination[scopeName] = lastValue;
26382643
}
26392644
break;
26402645

test/ng/compileSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -2675,6 +2675,24 @@ describe('$compile', function() {
26752675
expect(element.isolateScope()['watch']).toBe('watch');
26762676
})
26772677
);
2678+
2679+
it('should handle @ bindings on BOOLEAN attributes', function() {
2680+
var checkedVal;
2681+
module(function($compileProvider) {
2682+
$compileProvider.directive('test', function() {
2683+
return {
2684+
scope: { checked: '@' },
2685+
link: function(scope, element, attrs) {
2686+
checkedVal = scope.checked;
2687+
}
2688+
};
2689+
});
2690+
});
2691+
inject(function($compile, $rootScope) {
2692+
$compile('<input test checked="checked">')($rootScope);
2693+
expect(checkedVal).toEqual(true);
2694+
});
2695+
});
26782696
});
26792697

26802698

0 commit comments

Comments
 (0)