我想獲得的id在此基礎上在URL角2觀察到的問題
設置工作的附加模式,但得到錯誤編輯
export class GradeComponent implements OnInit {
public isNew:boolean=true;
public frmGrade: FormGroup;
public subscription:any;
public oldGrade:Grade;
constructor(
private formBuilder:FormBuilder ,
private gradeService:GradeService,
private router:Router,
private activatedRoute:ActivatedRoute
) { }
ngOnInit() {
if(typeof this.activatedRoute.snapshot.params['id'] ==='undefined'){
this.frmGrade = this.formBuilder.group({
grade: ['', Validators.required],
description: ''
});
}else{
this.setForUpdate();
}
}
private setForUpdate(){
this.isNew=false;
this.gradeService
.getOneGrade(this.activatedRoute.snapshot.params['id'])
.subscribe(
data => {
this.oldGrade = data,
this.frmGrade = this.formBuilder.group({
grade: [this.oldGrade.grade, Validators.required],
description: this.oldGrade.description
});
},
err => console.error(err),
() => console.log('done')
);
}
上的數據,但我得到的錯誤 這.formBuilder未定義如何處理這個。
'this.formBuilder'不會出現;-)爲什麼你認爲它應該在那裏? –
更新記錄,我想從ID獲取舊數據,然後分配給frm – Ash
什麼形式? 。 。 ..。 –