我想从医生的名字中选择任何选项,并单击任何名称,则div应该加载。应该为每个选择的选项加载新的div。
<select
class="docName"
[(ngModel)]="selectedID"
(ngModelChange)="doctorId($event)">
<option disabled> Select Doctor</option>
<option
*ngFor="let name of doctor"
id="{{ name.user_id }}"
[ngValue]="name">
{{ name.doctor_name }}
</option>
</select>
<div>show this data</div>
TScode,用于显示医生姓名:
doctorId(doctor_Id) {
this.delete = false;
if (doctor_Id === "All") {
this.doctorID = doctor_Id;
this.delete = true;
} else {
this.doctorID = doctor_Id.user_id;
this.delete = false;
}
只需使用CommonModule中的* ngIf。始终尝试保持简单。示例:
<div *ngIf="doctorID">{{doctorID}}</div> // Display what ever you want after a selection was mage
未选择医生时,将医生ID设置为undefined
或null
。>