Angular 选择框的面片值(角度9)
我正在尝试使用反应式表单修补编辑表单中的值。我可以控制该值,但它没有绑定到我的html。如果我在输入框中尝试相同的操作,我就能看到值。有人能告诉我哪里出了问题吗Angular 选择框的面片值(角度9),angular,typescript,Angular,Typescript,我正在尝试使用反应式表单修补编辑表单中的值。我可以控制该值,但它没有绑定到我的html。如果我在输入框中尝试相同的操作,我就能看到值。有人能告诉我哪里出了问题吗 patchGrowLicense(licenseObj) { console.log(licenseObj.landId); this.httpService.getAllFarmById(licenseObj.landId).subscribe(response => { this.farmObj =
patchGrowLicense(licenseObj) {
console.log(licenseObj.landId);
this.httpService.getAllFarmById(licenseObj.landId).subscribe(response => {
this.farmObj = response;
console.log(this.farmObj.street + ' , ' + this.farmObj.suburb + ' , ' + this.farmObj.town);
this.formGrowLicense.patchValue({
town:this.secondFormLocation.value.propertyName,
growLicFromLoc: this.farmObj.street + ' , ' + this.farmObj.suburb + ' , ' + this.farmObj.town,
});
});
}
getAllFarmLocations() {
this.httpService.getAllFarmLocations().subscribe(response => {
this.locations = response;
console.log(this.locations);
});
}
html
农场位置
选择耕作地点
{{地点.街道+”,“+地点.郊区+”,“+地点.城镇}
请输入农场位置
看这里
<option *ngFor="let location of locations" [value]=location.premisesId>
设置
select
的值时,必须有一个值为farmObj.street+'、“+farmObj.郊区+”、“+farmObj.town
在那里@nevzatopcu的选项,您可以尝试检查此行的控制台输出console.log(this.locations.find(location=>location.premisesId===this.farmObj.street+,“+this.farmObj.郊区+,”+this.farmObj.town);
我想它会返回null
。将它放在patchValue方法之后。您需要将值作为响应进行修补。premisesId或者如果您没有,您需要找到所选位置的premisesId
@nevzatopcu它工作正常。实际上我正在传递id以获取位置。因此我需要字符串。我可以检查如果我在输入字段中尝试formcontrol,也是一样的
<option *ngFor="let location of locations" [value]=location.premisesId>
this.formGrowLicense.patchValue({
town:this.secondFormLocation.value.propertyName,
growLicFromLoc: this.farmObj.id,
});