【发布时间】:2021-03-29 04:02:51
【问题描述】:
这是我正在使用的HTML 文件p-dropdown:
<p-dropdown id="userType"
name="userType"
inputId="userType"
formControlName="userType"
[required]="true"
[tabindex]="1"
optionLabel="title"
dataKey="id"
[options]="userTypeList"
placeholder="{{'Select user Type'|translate}}"
dropdownIcon="pi pi-caret-down"
(onChange)="onUserTypeChange($event)">
</p-dropdown>
在我的ts 文件中,我正在通过array 填充下拉列表:
ngAfterViewInit() {
this.getUserTypeList();
}
getUserTypeList(){
this.userTypeList = [
{ 'id': 'BankStaff', 'title': 'Bank Staff' },
{ 'id': 'DoerStaff', 'title': 'Doer Staff' }
]
}
刷新页面时选择用户类型后没有设置默认值总是抓取我之前选择的值。
我尝试像这样重置ngOnInit 中的表单:
ngOnInit(): void {
this.viFG.reset(this.viFG.value);
}
刷新后,我想将我的默认下拉值设置为“选择用户类型”,这是p-dropdown的占位符。
【问题讨论】:
-
你能在 Stackblitz 上重现这个问题吗?
标签: angular angular-reactive-forms angular9 angular10