0

我正在尝试在 ngOnInit() 方法中设置表单值。但出现错误 - 错误错误:尚未在该组中注册表单控件。如果您使用的是 ngModel,您可能需要检查下一个刻度(例如使用 setTimeout)。

ngOnInit() {
// this.index = +this.route.snapshot.params['index'];
// console.log("index value in form is "+this.index);
this.subscription = this.sharedService.startedEditing
  .subscribe((index: number) => {
       this.editIndex = index;
        this.editMode = true;
        this.editedTestCase = 
this.sharedService.getTestCase(this.editIndex);
        console.log("Inside ngonint for editing ");
        console.log(this.editedTestCase);

        setTimeout(() => {
          this.testForm.setValue({
            testid: this.editedTestCase.testid,
            testPriority: this.editedTestCase.testPriority,
            testSummary: this.editedTestCase.testSummary
        });
        });


     this.router.navigate(['form']);     
  });
}
4

0 回答 0