parent
d73734dcb7
commit
a84a9ba705
@ -34,8 +34,9 @@ import {Directive, DoCheck, ElementRef, Input, KeyValueChanges, KeyValueDiffer,
|
|||||||
* @description
|
* @description
|
||||||
*
|
*
|
||||||
* An attribute directive that updates styles for the containing HTML element.
|
* An attribute directive that updates styles for the containing HTML element.
|
||||||
* Sets one or more style properties, specified as key-value pairs.
|
* Sets one or more style properties, specified as colon-separated key-value pairs.
|
||||||
* The key is a style name, with an optional `.<unit>` suffix (such as 'top.px', 'font-style.em').
|
* The key is a style name, with an optional `.<unit>` suffix
|
||||||
|
* (such as 'top.px', 'font-style.em').
|
||||||
* The value is an expression to be evaluated.
|
* The value is an expression to be evaluated.
|
||||||
* The resulting non-null value, expressed in the given unit,
|
* The resulting non-null value, expressed in the given unit,
|
||||||
* is assigned to the given style property.
|
* is assigned to the given style property.
|
||||||
@ -54,13 +55,24 @@ export class NgStyle implements DoCheck {
|
|||||||
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer2) {}
|
private _differs: KeyValueDiffers, private _ngEl: ElementRef, private _renderer: Renderer2) {}
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set ngStyle(values: {[key: string]: string}) {
|
set ngStyle(
|
||||||
|
/**
|
||||||
|
* An array of style properties, specified as colon-separated
|
||||||
|
* key-value pairs.
|
||||||
|
* * The key is a style name, with an optional `.<unit>` suffix
|
||||||
|
* (such as 'top.px', 'font-style.em').
|
||||||
|
* * The value is an expression to be evaluated.
|
||||||
|
*/
|
||||||
|
values: {[key: string]: string}) {
|
||||||
this._ngStyle = values;
|
this._ngStyle = values;
|
||||||
if (!this._differ && values) {
|
if (!this._differ && values) {
|
||||||
this._differ = this._differs.find(values).create();
|
this._differ = this._differs.find(values).create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the new styles if needed.
|
||||||
|
*/
|
||||||
ngDoCheck() {
|
ngDoCheck() {
|
||||||
if (this._differ) {
|
if (this._differ) {
|
||||||
const changes = this._differ.diff(this._ngStyle);
|
const changes = this._differ.diff(this._ngStyle);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user