-2

I have a drop down which by default on page load it select "PLEASE SELECT USECASE" in the dropdown

enter image description here

But i am expecting "EUC Proxy" to be selected on page load instead of "PLEASE SELECT USECASE"

enter image description here

HTML IS SHOWN BELOW

<div class="form-group">
                            <label for="bot">Use Case</label>
                            <select id="select" formControlName="useCase" class="form-control" class="form-control" [(ngModel)]="scheduleModel.UsecaseId">
                                <option value="-1" [selected]="isSelected"> Please Select Use Case </option>
                                <option *ngFor="let uc of useCaseList"  [value]="uc.BOTId"> {{uc.BOTName}}
                                </option>
                            </select>
                        </div>
                    </div>

*HTML i CHANGED TO *

[selected]="1"

But it doesn't made any difference.See the changed HTML Below

 <div class="form-group">
                                <label for="bot">Use Case</label>
                                <select id="select" formControlName="useCase" class="form-control" class="form-control" [(ngModel)]="scheduleModel.UsecaseId">
                                                                            <option *ngFor="let uc of useCaseList" [selected]="1" [value]="uc.BOTId"> {{uc.BOTName}}
                                    </option>
                                </select>
                            </div>
                        </div>

SAME IN IMAGE enter image description here

I am getting "test Bot" selected in drop-down, which is last item in the drop down like below:

enter image description here

But i am expecting this: where uc.BOTId =1 is "EUC Proxy" Not "test Bot"

enter image description here

TS file

 ngOnInit() {
  getUsecaseList() {
      this.manageBotService.getAllBots().subscribe(res => this.useCaseList = res);

  }
}

Why i am unable to select "EUC Proxy" which having uc.BOTId =1 on page load?

SmartestVEGA
  • 8,415
  • 26
  • 86
  • 139

3 Answers3

1

Remove [selected] from your options.

The [(ngModel)] part from your 'select' will set the value to selected (depending on the value the 'scheduleModel.UsecaseId' has.

Bert Maurau
  • 979
  • 5
  • 21
1

I didn't see you using the instruction that makes it default:

value='default' 

for instance:

<select name='test'>
<option value='default' selected='selected'>Please select the value</option>
<option value='value1'>value1</option>
<option value='value2'>value2</option>
</select>
Vin Aeoua
  • 11
  • 4
1

Set scheduleModel.UsecaseId = 1 after loading the drop-down on ng-init().

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234