如何在primeNg动态对话框中访问动态数据



我正在使用 primeNg 的动态对话框,我必须将组件 A 中的 2 个变量传递到我从 A 动态打开的组件 B 中:

showSkillDetailModal(categoryId: number, skillId: number) {
const ref = this.dialogService.open(SkillDetailsComponent, {
width: '70%',
data: {
categoryId: categoryId,
skillId: skillId 
}
});
}

这是打开动态对话框的代码SkillDetailsComponent我发送的数据在数据数组中 ->categoryId & skillId

constructor(
public ref: DynamicDialogRef,
public config: DynamicDialogConfig,
private selfService: SelfDataService
) {}
ngOnInit() {
this.selfService.getMySkillList(categoryId, skillId).subscribe(response => {
}, error => {
console.log(error);
})
}

但是我无法在SkillDetailsComponent中获得这两个变量.关于如何在这方面向前迈进的任何想法?

可以像这样访问:

this.config.data.categoryId, this.config.data.skillId

您在DynamicDialog中提供的数据可以通过在组件中注入DynamicDialogConfig来访问,您可以通过以下DynamicDialog打开该组件:

constructor(public config: DynamicDialogConfig) {}
ngOnInit() {
console.log(this.config.data)
}

你可以试试这个:

在组件 A 中:

showSkillDetailModal(categoryId: number, skillId: number) {
const ref = this.dialogService.open(SkillDetailsComponent, {
width: '70%',
data: {
categoryId: categoryId,
skillId: skillId 
}
});

}

在组件 B 中:

constructor(
public ref: DynamicDialogRef,
public config: DynamicDialogConfig,
private selfService: SelfDataService
) {}
categoryId:number;
skillId:number;
ngOnInit() {
this.categoryId = this.config.data.categoryId;
this.skillId = this.config.data.skillId
this.selfService.getMySkillList(
this.categoryId,this.skillId).subscribe(response => {},error => {                             
console.log(error);
})
}

最新更新