这是因为由于 getPersonById 方法的异步特性。当您订阅它时,订阅块内的回调函数会在数据可用时执行,这意味着表单控件会在订阅之前使用人员的数据进行初始化。数据已获取。
ngOnInit(){
this.personService.getPersonById(this.guard.person_id).subscribe((person) => {
this.person = person
this.editPersonForm = this.fb.group({
surname: [this.person.surname,Validators.required],
name: [this.person.name,Validators.required],
father_name: this.person.father_name,
birthdate: this.person.birthdate,
phone_num: this.person.phone_number,
})
});