Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 选择框的面片值(角度9)_Angular_Typescript - Fatal编程技术网

Angular 选择框的面片值(角度9)

Angular 选择框的面片值(角度9),angular,typescript,Angular,Typescript,我正在尝试使用反应式表单修补编辑表单中的值。我可以控制该值,但它没有绑定到我的html。如果我在输入框中尝试相同的操作,我就能看到值。有人能告诉我哪里出了问题吗 patchGrowLicense(licenseObj) { console.log(licenseObj.landId); this.httpService.getAllFarmById(licenseObj.landId).subscribe(response => { this.farmObj =

我正在尝试使用反应式表单修补编辑表单中的值。我可以控制该值,但它没有绑定到我的html。如果我在输入框中尝试相同的操作,我就能看到值。有人能告诉我哪里出了问题吗

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,
      });