[Fixed] Angular Conditions in [style.width.px]


I currently have this code:

<div [style.width.px]="width1">
  <div>Something here</div>

But I need to put a condition like:

<div *ngIf="somecondition then [style.width.px]="width1" else [style.width.px]="width2" ">something here</div>

How can I do this?


You can simply use conditional expression that will return desired value:

<div [style.width.px]="someCondition ? width1 : width2">
  <div>Something here</div>

Leave a Reply

(*) Required, Your email will not be published