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

Commit bcb9fde

Browse files
committed
fixup! fix($compile): fix ng-prop-* with undefined values
1 parent 2998b1f commit bcb9fde

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/ng/compile.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3841,7 +3841,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
38413841
if (propValue !== undefined) {
38423842
$element.prop(propName, propValue);
38433843
} else {
3844-
delete $element[0][propName];
3844+
if ($element.removeProp) {
3845+
$element.removeProp(propName);
3846+
} else {
3847+
delete $element[0][propName];
3848+
}
38453849
}
38463850
}
38473851

test/ng/ngPropSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,23 @@ describe('ngProp*', function() {
9090
expect(element[0].hasOwnProperty('text')).toBe(false);
9191
}));
9292

93+
// Ensure jQuery prop/removeProp are used to support fix/hooks
94+
if (angular.element.prototype.removeProp) {
95+
it('should use jQuery.fn.prop() and jQuery.fn.removeProp() to support jQuery.propFix/Hooks', inject(function($rootScope, $compile) {
96+
$compile('<span ng-prop-text="myText" />')($rootScope);
97+
spyOn(angular.element.fn, 'prop').and.callThrough();
98+
spyOn(angular.element.fn, 'removeProp').and.callThrough();
99+
100+
$rootScope.myText = 'a value';
101+
$rootScope.$digest();
102+
expect(angular.element.fn.prop).toHaveBeenCalledWith('text', 'a value');
103+
104+
$rootScope.myText = undefined;
105+
$rootScope.$digest();
106+
expect(angular.element.fn.removeProp).toHaveBeenCalledWith('text');
107+
}));
108+
}
109+
93110
it('should support mixed case using underscore-separated names', inject(function($rootScope, $compile) {
94111
var element = $compile('<span ng-prop-a_bcd_e="value" />')($rootScope);
95112
$rootScope.value = 123;

0 commit comments

Comments
 (0)