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

3
  • 2
    You can check the length of the array <span>{{car.doors.length}}</span> Commented Jan 8, 2018 at 14:42
  • Possible duplicate of jQuery count child elements Commented Jan 8, 2018 at 14:43
  • Do you know if it is possible to do something like *ngIF="scenario.lIntConf.length>30" ? Commented Jan 8, 2018 at 14:58

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Just add '*ngIf="car.doors.length > 2". This will display the select when there are more than 2 elements and the doors array. @MarioLópez

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.