Angular 下拉菜单 - 反应式格式化页面
Angular Dropdown menu- reactive formatted page
我正在尝试显示一个下拉菜单,但由于某种原因选项列表未填充。如果我直接在 html 中显示 user.repList 它会正确显示,所以我知道列表不为空。我一定是错误地调用了表单,但我不知道如何调用。我究竟做错了什么?
型号
//initializes form which contains
repList: new FormControl(this.user.repList)
查看
<form [formGroup]="editUserForm" (ngSubmit)="onSubmit()">
<label>Choose Rep</label>
<select class="form-control" formControlName="repList" required>
<option *ngFor="let p of repList" [value]="p">{{p}}</option>
</select>
</form>
要显示 select 下拉菜单,您需要循环 user.repList。
<form [formGroup]="editUserForm" (ngSubmit)="onSubmit()">
<label>Choose Rep</label>
<select class="form-control" formControlName="repList" required>
<option *ngFor="let p of user.repList" [value]="p">{{p}}</option>
</select>
</form>
FormControl 需要有默认值/selected 值。
repList: new FormControl('');
我正在尝试显示一个下拉菜单,但由于某种原因选项列表未填充。如果我直接在 html 中显示 user.repList 它会正确显示,所以我知道列表不为空。我一定是错误地调用了表单,但我不知道如何调用。我究竟做错了什么?
型号
//initializes form which contains
repList: new FormControl(this.user.repList)
查看
<form [formGroup]="editUserForm" (ngSubmit)="onSubmit()">
<label>Choose Rep</label>
<select class="form-control" formControlName="repList" required>
<option *ngFor="let p of repList" [value]="p">{{p}}</option>
</select>
</form>
要显示 select 下拉菜单,您需要循环 user.repList。
<form [formGroup]="editUserForm" (ngSubmit)="onSubmit()">
<label>Choose Rep</label>
<select class="form-control" formControlName="repList" required>
<option *ngFor="let p of user.repList" [value]="p">{{p}}</option>
</select>
</form>
FormControl 需要有默认值/selected 值。
repList: new FormControl('');