如何在模态中获得列表数据?



我想从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
}

相关内容

  • 没有找到相关文章

最新更新