angular 部分选项,选择任何选项时应加载新的 div
angular section option, new div should load when any option is selected
我想 select 医生姓名中的任何选项,
并且无论单击什么名称,都应该加载 div。新 div 应该为每个选项加载 selected.
<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;
} else {
this.doctorID = doctor_Id.user_id;
}
只需使用 CommonModule 中的 *ngIf。总是尽量保持简单。
示例:
<div *ngIf="doctorID">{{doctorID}}</div> // Display what ever you want after a selection was mage
如果没有选择医生,请将您的 doctorID 设置为 undefined
或 null
。
我想 select 医生姓名中的任何选项, 并且无论单击什么名称,都应该加载 div。新 div 应该为每个选项加载 selected.
<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;
} else {
this.doctorID = doctor_Id.user_id;
}
只需使用 CommonModule 中的 *ngIf。总是尽量保持简单。 示例:
<div *ngIf="doctorID">{{doctorID}}</div> // Display what ever you want after a selection was mage
如果没有选择医生,请将您的 doctorID 设置为 undefined
或 null
。