Skip to content

Commit

Permalink
refactor(common): remove usage of deprecated Renderer (angular#17528)
Browse files Browse the repository at this point in the history
PR Close angular#17528
  • Loading branch information
pkozlowski-opensource authored and mhevery committed Aug 21, 2017
1 parent 5a1b9a3 commit 55d151a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 10 additions & 5 deletions packages/common/src/directives/ng_class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, DoCheck, ElementRef, Input, IterableChanges, IterableDiffer, IterableDiffers, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer, ɵisListLikeIterable as isListLikeIterable, ɵstringify as stringify} from '@angular/core';
import {Directive, DoCheck, ElementRef, Input, IterableChanges, IterableDiffer, IterableDiffers, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer2, ɵisListLikeIterable as isListLikeIterable, ɵstringify as stringify} from '@angular/core';

/**
* @ngModule CommonModule
Expand Down Expand Up @@ -45,7 +45,7 @@ export class NgClass implements DoCheck {

constructor(
private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers,
private _ngEl: ElementRef, private _renderer: Renderer) {}
private _ngEl: ElementRef, private _renderer: Renderer2) {}

@Input('class')
set klass(v: string) {
Expand Down Expand Up @@ -132,11 +132,16 @@ export class NgClass implements DoCheck {
}
}

private _toggleClass(klass: string, enabled: any): void {
private _toggleClass(klass: string, enabled: boolean): void {
klass = klass.trim();
if (klass) {
klass.split(/\s+/g).forEach(
klass => { this._renderer.setElementClass(this._ngEl.nativeElement, klass, !!enabled); });
klass.split(/\s+/g).forEach(klass => {
if (enabled) {
this._renderer.addClass(this._ngEl.nativeElement, klass);
} else {
this._renderer.removeClass(this._ngEl.nativeElement, klass);
}
});
}
}
}
6 changes: 3 additions & 3 deletions packages/common/src/directives/ng_style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, DoCheck, ElementRef, Input, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer} from '@angular/core';
import {Directive, DoCheck, ElementRef, Input, KeyValueChanges, KeyValueDiffer, KeyValueDiffers, Renderer2} from '@angular/core';

/**
* @ngModule CommonModule
Expand Down Expand Up @@ -36,7 +36,7 @@ export class NgStyle implements DoCheck {
private _differ: KeyValueDiffer<string, string|number>;

constructor(
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer) {}
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer2) {}

@Input()
set ngStyle(v: {[key: string]: string}) {
Expand Down Expand Up @@ -65,6 +65,6 @@ export class NgStyle implements DoCheck {
const [name, unit] = nameAndUnit.split('.');
value = value != null && unit ? `${value}${unit}` : value;

this._renderer.setElementStyle(this._ngEl.nativeElement, name, value as string);
this._renderer.setStyle(this._ngEl.nativeElement, name, value as string);
}
}
4 changes: 2 additions & 2 deletions tools/public_api_guard/common/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export declare class NgClass implements DoCheck {
ngClass: string | string[] | Set<string> | {
[klass: string]: any;
};
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer);
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer2);
ngDoCheck(): void;
}

Expand Down Expand Up @@ -223,7 +223,7 @@ export declare class NgStyle implements DoCheck {
ngStyle: {
[key: string]: string;
};
constructor(_differs: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer);
constructor(_differs: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer2);
ngDoCheck(): void;
}

Expand Down

0 comments on commit 55d151a

Please sign in to comment.