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

fix(ngStyle): skip setting empty value when new style has the property #16709

Merged
merged 7 commits into from
Oct 4, 2018
6 changes: 5 additions & 1 deletion src/ng/directive/ngStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@
var ngStyleDirective = ngDirective(function(scope, element, attr) {
scope.$watchCollection(attr.ngStyle, function ngStyleWatchAction(newStyles, oldStyles) {
if (oldStyles && (newStyles !== oldStyles)) {
forEach(oldStyles, function(val, style) { element.css(style, '');});
forEach(oldStyles, function(val, style) {
if (!(newStyles && newStyles.hasOwnProperty(style))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if newStyles does have the property, but the value is undefined or null?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, in that case the style should be cleared. Fixed in 5d74f0f.

element.css(style, '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect indentation.

}
});
}
if (newStyles) element.css(newStyles);
});
Expand Down