1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

use ngSwitch with on object with conditional attributes in Angular2

Discussão em 'Angular' iniciado por Fredje, Setembro 27, 2024.

  1. Fredje

    Fredje Guest

    I am making an Angular2 application and am retrieving an array of devices from the server. Not every device has the attribute 'brand' or 'type'. I want to display either of them, but in case they both miss I want to display 'Device #'. I tried to use an ngSwitch, but can't seem to make it work...

    <div *ngFor="let device of devices; let i=index">
    <div [ngSwitch]="device">
    <a *ngSwitchCase="device.brand">{{device.brand}}</a>
    <a *ngSwitchCase="device.type">{{device.type}}</a>
    <a *ngSwitchDefault>Device {{i+1}}</a>
    </div>
    </div>

    Continue reading...

Compartilhe esta Página