mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-01-12 22:45:52 +08:00
fix($compile): Handle the removal of an interpolated attribute
Handle the removal of an interpolated attribute before the attribute interpolating directive is linked Closes #9236 Closes #9240
This commit is contained in:
committed by
Igor Minar
parent
e843ae7a4c
commit
a75546afdf
@@ -2291,6 +2291,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
|
||||
"ng- versions (such as ng-click instead of onclick) instead.");
|
||||
}
|
||||
|
||||
// If the attribute was removed, then we are done
|
||||
if (!attr[name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// we need to interpolate again, in case the attribute value has been updated
|
||||
// (e.g. by another directive's compile function)
|
||||
interpolateFn = $interpolate(attr[name], true, getTrustedContext(node, name),
|
||||
|
||||
@@ -2547,6 +2547,24 @@ describe('$compile', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should allow the attribute to be removed before the attribute interpolation', function () {
|
||||
module(function() {
|
||||
directive('removeAttr', function () {
|
||||
return {
|
||||
restrict:'A',
|
||||
compile: function (tElement, tAttr) {
|
||||
tAttr.$set('removeAttr', null);
|
||||
}
|
||||
};
|
||||
});
|
||||
});
|
||||
inject(function ($rootScope, $compile) {
|
||||
expect(function () {
|
||||
element = $compile('<div remove-attr="{{ toBeRemoved }}"></div>')($rootScope);
|
||||
}).not.toThrow();
|
||||
expect(element.attr('remove-attr')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('SCE values', function() {
|
||||
it('should resolve compile and link both attribute and text bindings', inject(
|
||||
|
||||
Reference in New Issue
Block a user