1

I would like to know the number of elements (in this case option) has my select

<select class="form-control" required>
    <option *ngFor="let numberDoor of car.doors" type="text">{{numberDoor .number}}</option>
</select>

That is the select but I would like to check first if it has more than an element, or less (0 or 1) doors

I guess the easiest way is using Jquery or Javascript

bellotas
  • 2,349
  • 8
  • 29
  • 60

1 Answers1

2

Try like this:

<select class="form-control" required *ngIf='car.doors.length'> 
    <option *ngFor="let numberDoor of car.doors" type="text">{{numberDoor.number}}</option>
</select>

If car.doors are empty, your select don't display.

msanford
  • 11,803
  • 11
  • 66
  • 93
Dmitry Sobolevsky
  • 1,171
  • 6
  • 12