Skip to content

Commit 77a8807

Browse files
fix($compile): handle boolean attributes in @ bindings
Closes angular#13767
1 parent a1ff358 commit 77a8807

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/ng/compile.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -2956,10 +2956,13 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
29562956
}
29572957
});
29582958
attrs.$$observers[attrName].$$scope = scope;
2959-
if (isString(attrs[attrName])) {
2959+
lastValue = attrs[attrName];
2960+
if (isString(lastValue)) {
29602961
// If the attribute has been provided then we trigger an interpolation to ensure
29612962
// the value is there for use in the link fn
2962-
destination[scopeName] = $interpolate(attrs[attrName])(scope);
2963+
destination[scopeName] = $interpolate(lastValue)(scope);
2964+
} else if (isBoolean(lastValue)) {
2965+
destination[scopeName] = lastValue;
29632966
}
29642967
break;
29652968

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)