Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can the condition be reduced to one line?

I set the condition like this:

<mat-chip-list>
    <mat-chip color="accent" *ngIf="letter.status == 'Completed'" selected>
        {{ letter.status }}
    </mat-chip>
    <mat-chip color="warn" *ngIf="letter.status == 'In Work'" selected>
        {{letter.status }}
    </mat-chip>
</mat-chip-list>

Is it possible to reduced it down so it looks something like this:

<mat-chip color="letter.status == 'Completed' ? accent : warn" selected>
    {{ letter.status }}
</mat-chip>

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

@Input() color: ThemePalette Theme color palette for the component.

color is an input property

color="accent" static
[color]="expr ? 'accent' : 'warn'" dynamic

<mat-chip-list>
  <mat-chip
    [color]="letter.status == 'Completed' ? 'accent' : 'warn'"
    selected
    selected
  >
    {{ letter.status }}
  </mat-chip>
</mat-chip-list>

Stackblitz

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading