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

Commit db5e0ff

Browse files
fix($compile): handle boolean attributes in @ bindings
Closes #13767 Closes #13769
1 parent 92e4801 commit db5e0ff

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
@@ -2969,10 +2969,15 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
29692969
}
29702970
});
29712971
attrs.$$observers[attrName].$$scope = scope;
2972-
if (isString(attrs[attrName])) {
2972+
lastValue = attrs[attrName];
2973+
if (isString(lastValue)) {
29732974
// If the attribute has been provided then we trigger an interpolation to ensure
29742975
// the value is there for use in the link fn
2975-
destination[scopeName] = $interpolate(attrs[attrName])(scope);
2976+
destination[scopeName] = $interpolate(lastValue)(scope);
2977+
} else if (isBoolean(lastValue)) {
2978+
// If the attributes is one of the BOOLEAN_ATTR then Angular will have converted
2979+
// the value to boolean rather than a string, so we special case this situation
2980+
destination[scopeName] = lastValue;
29762981
}
29772982
break;
29782983

test/ng/compileSpec.js

+18
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,24 @@ describe('$compile', function() {
26942694
expect(element.isolateScope()['watch']).toBe('watch');
26952695
})
26962696
);
2697+
2698+
it('should handle @ bindings on BOOLEAN attributes', function() {
2699+
var checkedVal;
2700+
module(function($compileProvider) {
2701+
$compileProvider.directive('test', function() {
2702+
return {
2703+
scope: { checked: '@' },
2704+
link: function(scope, element, attrs) {
2705+
checkedVal = scope.checked;
2706+
}
2707+
};
2708+
});
2709+
});
2710+
inject(function($compile, $rootScope) {
2711+
$compile('<input test checked="checked">')($rootScope);
2712+
expect(checkedVal).toEqual(true);
2713+
});
2714+
});
26972715
});
26982716

26992717

0 commit comments

Comments
 (0)