refactor(common): remove usage of deprecated Renderer (#17528)
PR Close #17528
This commit is contained in:
parent
5a1b9a34df
commit
55d151a82d
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* 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
|
* @ngModule CommonModule
|
||||||
@ -45,7 +45,7 @@ export class NgClass implements DoCheck {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers,
|
private _iterableDiffers: IterableDiffers, private _keyValueDiffers: KeyValueDiffers,
|
||||||
private _ngEl: ElementRef, private _renderer: Renderer) {}
|
private _ngEl: ElementRef, private _renderer: Renderer2) {}
|
||||||
|
|
||||||
@Input('class')
|
@Input('class')
|
||||||
set klass(v: string) {
|
set klass(v: string) {
|
||||||
@ -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();
|
klass = klass.trim();
|
||||||
if (klass) {
|
if (klass) {
|
||||||
klass.split(/\s+/g).forEach(
|
klass.split(/\s+/g).forEach(klass => {
|
||||||
klass => { this._renderer.setElementClass(this._ngEl.nativeElement, klass, !!enabled); });
|
if (enabled) {
|
||||||
|
this._renderer.addClass(this._ngEl.nativeElement, klass);
|
||||||
|
} else {
|
||||||
|
this._renderer.removeClass(this._ngEl.nativeElement, klass);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* found in the LICENSE file at https://angular.io/license
|
* 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
|
* @ngModule CommonModule
|
||||||
@ -36,7 +36,7 @@ export class NgStyle implements DoCheck {
|
|||||||
private _differ: KeyValueDiffer<string, string|number>;
|
private _differ: KeyValueDiffer<string, string|number>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer) {}
|
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer2) {}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set ngStyle(v: {[key: string]: string}) {
|
set ngStyle(v: {[key: string]: string}) {
|
||||||
@ -65,6 +65,6 @@ export class NgStyle implements DoCheck {
|
|||||||
const [name, unit] = nameAndUnit.split('.');
|
const [name, unit] = nameAndUnit.split('.');
|
||||||
value = value != null && unit ? `${value}${unit}` : value;
|
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
tools/public_api_guard/common/common.d.ts
vendored
4
tools/public_api_guard/common/common.d.ts
vendored
@ -138,7 +138,7 @@ export declare class NgClass implements DoCheck {
|
|||||||
ngClass: string | string[] | Set<string> | {
|
ngClass: string | string[] | Set<string> | {
|
||||||
[klass: string]: any;
|
[klass: string]: any;
|
||||||
};
|
};
|
||||||
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer);
|
constructor(_iterableDiffers: IterableDiffers, _keyValueDiffers: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer2);
|
||||||
ngDoCheck(): void;
|
ngDoCheck(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +223,7 @@ export declare class NgStyle implements DoCheck {
|
|||||||
ngStyle: {
|
ngStyle: {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
};
|
};
|
||||||
constructor(_differs: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer);
|
constructor(_differs: KeyValueDiffers, _ngEl: ElementRef, _renderer: Renderer2);
|
||||||
ngDoCheck(): void;
|
ngDoCheck(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user