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

Closes #13767
Closes #13769
This commit is contained in:
Peter Bacon Darwin
2016-01-14 14:32:54 +00:00
parent 92e4801d88
commit db5e0ffe12
2 changed files with 25 additions and 2 deletions
+7 -2
View File
@@ -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;
+18
View File
@@ -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);
});
});
});