2017-10-04 63 views
2

當我使用this.programTypeForm.setValue(programType)將響應值設置爲FormGroup varriable(programTypeForm)時,我得到了錯誤 「無法找到具有名稱的窗體控件:創建於。」在Subscriber.js文件錯誤:無法找到窗體控件的名稱:CreatedOn在Angular

this.programTypeForm = this.fb.group({ 
 
      VersionNumber:[null], 
 
      ProgramTypeID: [null], 
 
      ProgramTypeName: [null, Validators.required], 
 
      ProgramTypeEnglishName: [null, Validators.required], 
 
      OrganizationID: [null], 
 
      OrganizationHierarchyID: [null], 
 
      LanguageID: ["Asdf"], 
 
      UserID: [11], 
 
      CurrencyID:["Asdasd"] 
 
     });

if(this.programTypeId>0) 
 
     { 
 
     // alert(this.programTypeId); 
 
     this._userService.get("ProgramType/getProgramTypeDetailById/" + this.programTypeId) 
 
     .subscribe(programType => { 
 
      alert(programType.VersionNumber); 
 
      this.programTypeForm.setValue(programType); 
 
      console.log(programType); 
 
      
 
     }, 
 
     error => this.msg = <any>error); 
 
     }

+0

我猜的服務調用返回鍵CreatedOn的鍵值,您可以檢查 –

+0

顯示對象從服務 – porgo

+0

返回,但我不想使用角側的那場或關鍵CreatedOn那麼我需要做什麼 –

回答

0

正如在評論中提到,傳入的反應似乎有屬性CreatedOn,這是不包含在您的形式,從而錯誤。如果你想只從你的迴應挑選特定的屬性,你可以做到這一點通過修改setValue()到這樣的事情:

this.programTypeForm.setValue({ 
    VersionNumber: programType.VersionNumber, // here assuming the propertynames match... 
    ProgramTypeID: programType.ProgramTypeID, 
    // ... rest omitted 
}); 
0

您可以使用patchValuesetValue。像這樣:

this.programTypeForm.patchValue(programType); 
相關問題