Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ngStyle not getting applied

In my angular 5 app, [ngStyle] is not expanding to style attribute. I only see ng-reflect-ng-style. This used to work before. Did something change in the recent updates to Angular or Angular-cli?

This is template:

<div *ngIf="ready" class="card" [ngStyle]="dimensions">
</div

This is the generated HTML:

<div _ngcontent-c6="" class="card ng-tns-c6-1" ng-reflect-ng-style="[object Object]">

</div>

Expected, with dimensions = {width: '240px'}:

<div _ngcontent-c6="" class="card ng-tns-c6-1" ng-reflect-ng-style="[object Object]" style="width:240px">

</div>
like image 285
vrtx54234 Avatar asked Nov 27 '17 06:11

vrtx54234


1 Answers

You can use it in directly template-

[ngStyle]="{'width.px': 200}"

or

dimensions = {'width.px': 200};
<div *ngIf="ready" class="card" [ngStyle]="dimensions">
</div
like image 193
Akshay Garg Avatar answered Sep 21 '22 22:09

Akshay Garg