gpt4 book ai didi

angular - 将参数传递给 mat-dialog 打开方法

转载 作者:行者123 更新时间:2023-12-04 11:45:34 25 4
gpt4 key购买 nike

Angular 7.1 ,
AngularMaterial 7.3

我正在尝试调用函数并传递一些值,它提示以下错误

No component factory found for t1. Did you add it to @NgModule.entryComponents?



虽然 t1包含在 entryComponent 中.但是一旦删除传递值以修复值,它将起作用。
  <button mat-button (click)="openDialog('t1')">T1</button>
<button mat-button (click)="openDialog('t2')">T2</button>

一旦我传递了值,它就会显示上面的代码。
  openDialog(e) {
console.log(e);
const dialogRef = this.dialog.open(e);
dialogRef.afterClosed().subscribe(result => {
console.log(`Dialog result: ${result}`);
dialogRef == null
});
}

@Component({
selector: 't1',
templateUrl: 't1.html',
})
export class t1 {}

@Component({
selector: 't2',
templateUrl: 't2.html',
})
export class t2 {}

但是一旦我删除该值并修复 dialogRef.open ,它工作正常
const dialogRef = this.dialog.open(t1);

最佳答案

这对我有用。你也可以引用这个链接。 link
您可以使用 dialogRef.componentInstance.myProperty = 'some data'设置组件上的数据。
你可能需要这样的东西:

let dialogRef = this.dialog.open(DialogComponent, {
disableClose: true,
});
dialogRef.componentInstance.name = 'Sunil';

然后在你的 DialogComponent 你需要添加你的 name 属性:
public name: string;

关于angular - 将参数传递给 mat-dialog 打开方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54939352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com