我有一个下拉列表。
<select class="form-control" [(ngModel)]="UpdateTeacher.TeacherId" name="TeacherName" value={{UpdateTeacher.TeacherId}} required #TeacherName="ngModel">
<option *ngFor="let TeacherDetail of this.userService.TeacherDetails" value="{{TeacherDetail.TeacherId}}">
{{TeacherDetail.TeacherName}} </option>
</select>
现在this.userService.TeacherDetails是我正在迭代的一个Teacher对象数组。我已经在UpdateTeacher.TeacherId中设置了一个值为2当显示下拉2选项时必须预选。怎么实现呢? 提前致谢。
答案 0 :(得分:3)
值应写为输入sig(df)
df pos
[1,] 1 0
[2,] 2 0
[3,] 3 0
[4,] 4 4
[5,] 5 5
[6,] 6 6
[7,] 7 7
[8,] 8 8
[9,] 9 9
[10,] 10 10
即
[value]="something"
答案 1 :(得分:0)
<select class="form-control" [(ngModel)]="UpdateTeacher.TeacherId" name="TeacherName" value={{UpdateTeacher.TeacherName}} required
#TeacherName="ngModel">
<option *ngFor="let TeacherDetail of this.userService.TeacherDetails" selected="{{UpdateTeacher.TeacherId == TeacherDetail.TeacherId}}"
value="{{TeacherDetail.TeacherId}}">
{{TeacherDetail.TeacherName}} </option>
</select>