Skip to content

Commit

Permalink
fix(core): allow null value for renderer setElement(…)
Browse files Browse the repository at this point in the history
Using Renderer’s setElementAttribute or setElementStyle with a null or undefined value removes the
corresponding attribute or style. The argument type should allow this when using strictNullChecks.

Closes angular#13686
  • Loading branch information
Manduro authored and mhevery committed Jul 26, 2017
1 parent 205abe8 commit 40228b5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/render/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export abstract class Renderer {

abstract setElementProperty(renderElement: any, propertyName: string, propertyValue: any): void;

abstract setElementAttribute(renderElement: any, attributeName: string, attributeValue: string):
abstract setElementAttribute(renderElement: any, attributeName: string, attributeValue?: string):
void;

/**
Expand All @@ -81,7 +81,7 @@ export abstract class Renderer {

abstract setElementClass(renderElement: any, className: string, isAdd: boolean): void;

abstract setElementStyle(renderElement: any, styleName: string, styleValue: string): void;
abstract setElementStyle(renderElement: any, styleName: string, styleValue?: string): void;

abstract invokeElementMethod(renderElement: any, methodName: string, args?: any[]): void;

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/view/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ class RendererAdapter implements RendererV1 {
this.delegate.setProperty(renderElement, propertyName, propertyValue);
}

setElementAttribute(renderElement: Element, namespaceAndName: string, attributeValue: string):
setElementAttribute(renderElement: Element, namespaceAndName: string, attributeValue?: string):
void {
const [ns, name] = splitNamespace(namespaceAndName);
if (attributeValue != null) {
Expand All @@ -439,7 +439,7 @@ class RendererAdapter implements RendererV1 {
}
}

setElementStyle(renderElement: HTMLElement, styleName: string, styleValue: string): void {
setElementStyle(renderElement: HTMLElement, styleName: string, styleValue?: string): void {
if (styleValue != null) {
this.delegate.setStyle(renderElement, styleName, styleValue);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tools/public_api_guard/core/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,10 @@ export declare abstract class Renderer {
abstract projectNodes(parentElement: any, nodes: any[]): void;
abstract selectRootElement(selectorOrNode: string | any, debugInfo?: RenderDebugInfo): any;
abstract setBindingDebugInfo(renderElement: any, propertyName: string, propertyValue: string): void;
abstract setElementAttribute(renderElement: any, attributeName: string, attributeValue: string): void;
abstract setElementAttribute(renderElement: any, attributeName: string, attributeValue?: string): void;
abstract setElementClass(renderElement: any, className: string, isAdd: boolean): void;
abstract setElementProperty(renderElement: any, propertyName: string, propertyValue: any): void;
abstract setElementStyle(renderElement: any, styleName: string, styleValue: string): void;
abstract setElementStyle(renderElement: any, styleName: string, styleValue?: string): void;
abstract setText(renderNode: any, text: string): void;
}

Expand Down

0 comments on commit 40228b5

Please sign in to comment.