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

Commit 2b542de

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

File tree

2 files changed

+1
-43
lines changed

2 files changed

+1
-43
lines changed

src/ng/compile.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3836,17 +3836,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
38363836
return {
38373837
pre: function ngPropPreLinkFn(scope, $element) {
38383838
function applyPropValue() {
3839-
var propValue = sanitizer(ngPropGetter(scope));
3840-
3841-
if (propValue !== undefined) {
3842-
$element.prop(propName, propValue);
3843-
} else {
3844-
if ($element.removeProp) {
3845-
$element.removeProp(propName);
3846-
} else {
3847-
delete $element[0][propName];
3848-
}
3849-
}
3839+
$element[0][propName] = sanitizer(ngPropGetter(scope));
38503840
}
38513841

38523842
applyPropValue();

test/ng/ngPropSpec.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,38 +75,6 @@ describe('ngProp*', function() {
7575
expect(element.prop('text')).toBe(null);
7676
}));
7777

78-
// https://github.com/angular/angular.js/issues/16797
79-
it('should delete properties with undefined values', inject(function($rootScope, $compile) {
80-
var element = $compile('<span ng-prop-text="myText" />')($rootScope);
81-
expect(element[0].hasOwnProperty('text')).toBe(false);
82-
83-
$rootScope.myText = 'a value';
84-
$rootScope.$digest();
85-
expect(element.prop('text')).toBe('a value');
86-
expect(element[0].hasOwnProperty('text')).toBe(true);
87-
88-
$rootScope.myText = undefined;
89-
$rootScope.$digest();
90-
expect(element[0].hasOwnProperty('text')).toBe(false);
91-
}));
92-
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-
11078
it('should support mixed case using underscore-separated names', inject(function($rootScope, $compile) {
11179
var element = $compile('<span ng-prop-a_bcd_e="value" />')($rootScope);
11280
$rootScope.value = 123;

0 commit comments

Comments
 (0)