1

How can I set the default value as 'I am interested in', in the dropdown box. Here`s the code. I tried to remove name property also, but that`s not a good solution.

<div class="form-group">
  <select (blur) = "validateTopic(topic.value)" (change)="validateTopic(topic.value)" class="custom-select form-control" #topic="ngModel" [class.is-invalid]="topic.invalid && topic.touched" name="topic" [(ngModel)]="userModel.topic" required [value]="'I am interested in'">
    <option value='default' selected>I am interested in </option>
    <option *ngFor="let sub of topics">{{sub}}</option>
  </select>
  <small class="text-danger" [class.d-none]="!topicHasError && topic.touched">Please choose a topic</small>
</div>

Nothing is selected by default in the dropdown box.

1 Answers1

0
 <div class="form-group">
  <select (blur) = "validateTopic(topic.value)" (change)="validateTopic(topic.value)" class="custom-select form-control" #topic="ngModel" [class.is-invalid]="topic.invalid && topic.touched" name="topic" [(ngModel)]="userModel.topic" required [value]="'default'">
    <option value='default' selected>I am interested in </option>
    <option *ngFor="let sub of topics" [value]="sub">{{sub}}</option>
  </select>
  <small class="text-danger" [class.d-none]="!topicHasError && topic.touched">Please choose a topic</small>
</div>
Sameer
  • 509
  • 3
  • 16