[英]angular reactive forms - bind input element to reactive form programmatically
[英]reactive forms not bind dropdown if no interaction with form in angular
我有一个包含 3 个下拉列表的表单,这个下拉列表从 API 获取他们的数据问题是如果我不点击下拉列表,下拉列表不会绑定数据(表单中的任何字段都模糊)
我的 HTML
<form [formGroup]="dropdownsForm" novalidate class="needs-validation">
<div class="dropdown">
<select class="form-control" formControlName="CountryName"
[attr.data-live-search]="true" style="width: 150px;" >
<option *ngFor="let Country of allCountrys" [value]="Country.id">
{{Country.title}}</option>
</select>
</div>
</form>
我的ts
allCountrys: DropDownListForLkpsDto[];
constructor(
private fb: FormBuilder,
private _countryService: CountryServiceProxy
) {
}
ngOnInit(): void {
this.dropdownsForm = this.fb.group(
{
CountryName: [""],
}
);
this._countryService.getAllCountrysForDDl().subscribe(result => {
this.allCountrys = result;
});
}
经过 3 天的搜索,我们终于在我的 ts 文件中找到了问题,当我们删除 changeDetection 行时,我有这一行changeDetection: ChangeDetectionStrategy.OnPush
into my @Component({ })
它工作正常
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.