我的问题是我得到的数据是可观察的,所以我检查数据是否 未定义,当它没有未定义时,我把它放入医生对象但是 我的一些代码在填充之前使用数据并生成错误,因为 value未定义如何获取变量中的响应值。
workingDayFilter = ( d: Date ): boolean => {
const day = d.getDay();
let workingDays = this.doctor.workingDays;
let result: boolean = false;
for ( let i = 0; i < workingDays.length; i++ ) {
if ( day == workingDays[i] ) {
result = true;
}
}
return result;
}
ngOnInit() {
this.getDoctor();
console.log( this.doctor );
this.appointmentForm = this.formBuilder.group( {
patientId: this.patientId,
date: this.date,
timeSlot: this.timeSlot
} );
}
public getDoctor() {
this.doctorService.getDoctorPublicInfo().subscribe(( data ) => {
if ( data != undefined ) {
this.doctor = data.json();
}
} );
}
答案 0 :(得分:0)
尝试这样的事情
ngOnInit() {
this.getDoctor().subscribe((data) => {
console.log(this.doctor);
this.appointmentForm = this.formBuilder.group({
patientId: this.patientId,
date: this.date,
timeSlot: this.timeSlot
});
})
};
public getDoctor() {
this.doctorService.getDoctorPublicInfo().map((resp) => {
if (resp != undefined) {
this.doctor = resp.json();
}
});
}