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

Commit

Permalink
fixup! fix($compile): fix ng-prop-* with undefined values
Browse files Browse the repository at this point in the history
  • Loading branch information
jbedard committed Dec 30, 2018
1 parent bcb9fde commit 2b542de
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 43 deletions.
12 changes: 1 addition & 11 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3836,17 +3836,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
return {
pre: function ngPropPreLinkFn(scope, $element) {
function applyPropValue() {
var propValue = sanitizer(ngPropGetter(scope));

if (propValue !== undefined) {
$element.prop(propName, propValue);
} else {
if ($element.removeProp) {
$element.removeProp(propName);
} else {
delete $element[0][propName];
}
}
$element[0][propName] = sanitizer(ngPropGetter(scope));
}

applyPropValue();
Expand Down
32 changes: 0 additions & 32 deletions test/ng/ngPropSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,6 @@ describe('ngProp*', function() {
expect(element.prop('text')).toBe(null);
}));

// https://github.com/angular/angular.js/issues/16797
it('should delete properties with undefined values', inject(function($rootScope, $compile) {
var element = $compile('<span ng-prop-text="myText" />')($rootScope);
expect(element[0].hasOwnProperty('text')).toBe(false);

$rootScope.myText = 'a value';
$rootScope.$digest();
expect(element.prop('text')).toBe('a value');
expect(element[0].hasOwnProperty('text')).toBe(true);

$rootScope.myText = undefined;
$rootScope.$digest();
expect(element[0].hasOwnProperty('text')).toBe(false);
}));

// Ensure jQuery prop/removeProp are used to support fix/hooks
if (angular.element.prototype.removeProp) {
it('should use jQuery.fn.prop() and jQuery.fn.removeProp() to support jQuery.propFix/Hooks', inject(function($rootScope, $compile) {
$compile('<span ng-prop-text="myText" />')($rootScope);
spyOn(angular.element.fn, 'prop').and.callThrough();
spyOn(angular.element.fn, 'removeProp').and.callThrough();

$rootScope.myText = 'a value';
$rootScope.$digest();
expect(angular.element.fn.prop).toHaveBeenCalledWith('text', 'a value');

$rootScope.myText = undefined;
$rootScope.$digest();
expect(angular.element.fn.removeProp).toHaveBeenCalledWith('text');
}));
}

it('should support mixed case using underscore-separated names', inject(function($rootScope, $compile) {
var element = $compile('<span ng-prop-a_bcd_e="value" />')($rootScope);
$rootScope.value = 123;
Expand Down

0 comments on commit 2b542de

Please sign in to comment.