How can I select a default dropdown option with a ternary condition?

338 views Asked by At

How can we use a ternary condition within the [selected] or [ngvalue] property of option in order to have a default selected option? For ex:

<input type="text" name="time">
<select class="form-control">
   <option [selected]="{time > 12 ? 'PM' : 'AM'}">
</select>

This default option is dependent on the input typed. If the input typed in the field is above 12, then it should automatically select PM, else AM.

1

There are 1 answers

0
Haseeb Javed On

handle time with Hook State.Like const time =