[英]how to pass a row data or the object of an array to a component in Angular using MatDialog
What I want is that, when I click on the specific row's button, it should open up a matDialog box which should display me all the contents of the row.我想要的是,当我单击特定行的按钮时,它应该打开一个 matDialog 框,该框应该显示该行的所有内容。 This is the html file ,
这是html文件,
<tr *ngFor="let u of users">
<td data-label="ID">{{u.name}}</td>
<td>
<button (click)="toggle(u)" mat-button type="button" class="btn btn-primary">
Show Details
</button>
</td>
</tr>
And this is my ts file .这是我的ts 文件。
users = [
{
'name':'arjun'
},
{
'name':'Karan'
}
]
toggle(userRow:any){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.width="60%";
this.dialog.open(UserDetailsPopupComponent, dialogConfig);
}
And this is my html file of the component( UserDetailsPopUp ) that will open using MatDialogue.这是我将使用 MatDialogue 打开的组件( UserDetailsPopUp )的html 文件。
<h1>Hello{{u.name}}</h1>
But I'm not able to send the row data from the toggle function to this component.但我无法将行数据从切换功能发送到此组件。 How do I do that?
我怎么做? And load that data and display it.
并加载该数据并显示它。
Send data to the dialog component like this:像这样将数据发送到对话框组件:
toggle(userRow:any){
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = false;
dialogConfig.autoFocus = true;
dialogConfig.width="60%";
dialogConfig.data = userRow;
this.dialog.open(UserDetailsPopupComponent, dialogConfig);
}
and to catch the data in UserDetailsPopupComponent
并捕获
UserDetailsPopupComponent
的数据
constructor(@Inject(MAT_DIALOG_DATA) public _data: any) {}
_data
contains the userRow
data. _data
包含userRow
数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.