Html 无法读取属性';设置值';未定义的|角的

Html 无法读取属性';设置值';未定义的|角的,html,angular,typescript,Html,Angular,Typescript,我的HTML组件有问题,由于某种原因,my方法显示错误: 当我单击编辑按钮时,无法读取未定义的属性“setValue”,但似乎一切正常 这是我的HTML <div *ngFor="let item of currentUser.myExperiences" class="mt-3"> <div> <h6>{{item.companyName}} <span *ngIf="item.currentlyWorking" c

我的HTML组件有问题,由于某种原因,my方法显示错误: 当我单击编辑按钮时,无法读取未定义的属性“setValue”,但似乎一切正常

这是我的HTML

<div *ngFor="let item of currentUser.myExperiences" class="mt-3">
        <div>
          <h6>{{item.companyName}} <span *ngIf="item.currentlyWorking" class="badge badge-warning">Currently
              working</span>
              <span class="float-right">
                <a class="text-warning cursor" (click)="openEditModal(item)"><i class="fas fa-pencil-alt"></i></a>
              </span>
            </h6>
          <p class="text-muted p-text-sm">{{item.functions}}</p>
          <p class="text-muted p-text-sm" *ngIf="item.references">
            <strong>References:</strong>
            {{item.references}}
          </p>
          <hr>
        </div>
      </div>

<form role="form" [formGroup]="updateForm">
        <div class="form-group">
          <label for="functions">Funtions</label>
          <input type="text" class="form-control" id="functions" name="functions" formControlName="functions" aria-describedby="emailHelp">
        </div>
        <div class="form-group">
          <label for="exampleInputPassword1">Password</label>
          <input type="password" class="form-control" id="exampleInputPassword1">
        </div>
        <button type="submit" class="btn btn-primary">Submit</button>
      </form>
我尝试在控制台中显示该对象,但它工作得很好,但我不确定为什么会发生这种情况

我使用解析器将信息从路由正确地传递到组件


提前谢谢

尝试使用this.updateForm.patchValue而不是this.updateForm.setValue

这是一个不完整的代码,this.experienceId是什么?在HTML文件中,“item”包含的对象与TS文件中的对象相同。问题是,当它被调试时,它会在HTMLI中显示错误。在您添加的问题中,我看不到它。您能为您的问题创建一个stackblitz吗?您能共享完整的TS文件吗?因为我不确定您代码段中某些对象(如experienceId、companyName等)的类型和定义。它似乎不起作用,它显示类似的错误:无法读取未定义的属性“patchValue”。奇怪的是console.log(myExperience);完美地显示对象。如果提供完整的代码,将更有帮助。
public openEditModal(myExperience: IMyExperience): void {
console.log(myExperience);
// Set values to controls
console.log(myExperience.id);
this.experienceId.setValue(myExperience.id);
this.companyName.setValue(myExperience.companyName);
this.functions.setValue(myExperience.functions);
this.workedYears.setValue(myExperience.workedYears);
this.references.setValue(myExperience.references);
this.currentlyWorking.setValue(myExperience.currentlyWorking);

this.updateForm.setValue({
  experienceId: this.experienceId.value,
  companyName: this.companyName.value,
  functions: this.functions.value,
  workedYears: this.workedYears.value,
  references: this.references.value,
  currentlyWorking: this.currentlyWorking.value
});

// Open the modal
this.modalRef = this.modalService.show(
  this.editModal,
  Object.assign({}, { class: 'gray modal-lg' })
);}