Flex-layout: ngStyle conflict with ngStyle.alias

Created on 1 May 2017  路  8Comments  路  Source: angular/flex-layout

Supposedly they are independent

<div
  [ngStyle]="{'transform': slideStyleString, 'transition': 'transform 0.75s ease-in-out'}"
  [ngStyle.xs]="{'color': 'green'}"
>TESTING</div>

However, if you can the value of slideStyleString above, the color will be lost.

Problem exists in 2.0.0-beta.7 and 2.0.0-beta.8.
Problem not present in 2.0.0-rc.1

See plunker. HTML is in src/app/test-app.ts
The first DIV stays in color. Click the slide out button and the second DIV loses color and turns black.

P2 has pr

Most helpful comment

@mackelito This fix will be available in Beta.10 (or new RC1 if we can overwrite the existing invalid one).

All 8 comments

An even simply example:

<div
  [ngStyle]="{'fontSize': sizeString}"
  [ngStyle.xs]="{'color': 'green'}"
  [ngStyle.sm]="{'color': 'red'}"
  [ngStyle.md]="{'color': 'blue'}"
  [ngStyle.lg]="{'color': 'purple'}"
  [ngStyle.xl]="{'color': 'pink'}"
>TESTING</div>
<button (click)='sizeString="20pt"'>Size 20</button>
<button (click)='sizeString="10pt"'>Size 10</button>   

@alexfung888 - While the ngStyle Wiki says styles will be merged. Let me confirm again Angular core expectations.

@ThomasBurleson Any progress on this one ?

@ThomasBurleson will this be fixed in the upcoming release?

@mackelito This fix will be available in Beta.10 (or new RC1 if we can overwrite the existing invalid one).

The latest nightly build provides fixes for ngStyle.

screen shot 2017-09-15 at 6 04 16 pm

See Plunkr Demo

<div
        [ngStyle]="{'fontSize': sizeString}"
        [ngStyle.xs]="{'color': 'green', 'fontSize': sizeString}"
        [ngStyle.sm]="{'color': 'red', 'fontSize': '12pt'}"
        [ngStyle.md]="{'color': 'blue'}"
        [ngStyle.lg]="{'color': 'purple'}"
        [ngStyle.xl]="{'color': 'pink'}" >
</div>

The responsive key can override a default property in ngStyle object and merge the responsive key/values with the initial default key values.

Note that the ngStyle.xs is the only breakpoint that will use dynamically changed font-sizes AND preserve the color. Otherwise the font-size will trigger the ngStyle to update and render WITHOUT color.

Per the ngStyle Directive in core, the ngStyle directive will replace anything in style; after first merging the initial style key-values into the any ngStyle key-values.

Using style + ngStyle

ngstyle

This is now working similar in functionality to [ngStyle] in core.

sample1

This functionality is available in the nightly build and will be released to npm with the [upcoming] Beta.10 release.

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings