fix($compile): handle boolean attributes in @ bindings
Closes #13767 Closes #13769
This commit is contained in:
+7
-2
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user