我想从getcategorie
函数中获得listCategorie
,并将其放在我的模态中,但它是空的!
如何解决这个问题?这是我的代码:
getcategorie() {
this.LCategorieService.getCategories(this.id).then((res )=> {
this.listCategorie = res;
})
}
async addNoteModal() {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.data = {
ismodal: true,
idExamen: this.id,
list:this.listCategorie ,
}; console.log('aaaaaa',this.list);
this.dialog.open(NoteModalComponent, dialogConfig);
try {
await this.getcategorie();
} catch (error) {
console.error(" failed", error);
}
}
LCategorieService服务:
getCategories(id: string): Promise<L_ExamenCategorie[]> {
const response = this.httpClient.get<L_ExamenCategorie[]>(this.baseUrl + '/findcategories/' + id).toPromise();
return response;
}
先呼叫getcategorie()
,再呼叫addNoteModal()
async addNoteModal() {
try {
await this.getcategorie();
} catch (error) {
console.error(" failed", error);
}
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.data = {
ismodal: true,
idExamen: this.id,
list:this.listCategorie ,
};
this.dialog.open(NoteModalComponent, dialogConfig);
}
在你的NoteModalComponent
中你需要得到这些数据
data: any;
constructor(
public dialogRef: MatDialogRef<NoteModalComponent>,
@Inject(MAT_DIALOG_DATA) public data: any
) {
this.data = data.list
}