Я новичок в angular. У меня есть таблица, которая содержит данные более 100 студентов (например: firstName, lastName, address, ... et c). Я хочу щелкнуть правой кнопкой мыши на studentDataTable (скажем, я щелкну правой кнопкой мыши на student7), и откроется всплывающее окно которые содержат данные student7 во всплывающем окне. Заранее спасибо.
Я уже написал код всплывающего окна, не в состоянии заполнить данные таблицы во всплывающее окно
Код для таблицы: Компонент: 1, откуда мы получаем данные об ученике ` `` import {Component} from '@ angular / core';
export interface studentData {
firstname: string;
position: number;
lastName: string;
Address:string;
contact:string;
Age:string;
}
const ELEMENT_DATA: studentData[] = [
{position: 1, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 2, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 3, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 4, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 5, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 6, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 7, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 8, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 9, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 10, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
{position: 11, firstname: 'Student1', lastName: 'study1', Address: 'address1',contact:'contact1',Age:'age1'},
];
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
displayedColumns: string[] = ['position', 'firstname','lastName','Address','contact','Age'];
dataSource = ELEMENT_DATA;
}```
HTML код для таблицы: часть компонента: 1
```<table mat-table [dataSource]="dataSource" class="mat-elevation-z8">
<ng-container matColumnDef="position">
<th mat-header-cell *matHeaderCellDef> No. </th>
<td mat-cell *matCellDef="let element"> {{element.position}} </td>
</ng-container>
<ng-container matColumnDef="firstname">
<th mat-header-cell *matHeaderCellDef> First Name </th>
<td mat-cell *matCellDef="let element"> {{element.name}} </td>
</ng-container>
<ng-container matColumnDef="lastName">
<th mat-header-cell *matHeaderCellDef> Last Name </th>
<td mat-cell *matCellDef="let element"> {{element.lastName}} </td>
</ng-container>
<ng-container matColumnDef="Address">
<th mat-header-cell *matHeaderCellDef> Address </th>
<td mat-cell *matCellDef="let element"> {{element.Address}} </td>
</ng-container>
<ng-container matColumnDef="contact">
<th mat-header-cell *matHeaderCellDef> ContactNo </th>
<td mat-cell *matCellDef="let element"> {{element.contact}} </td>
</ng-container>
<ng-container matColumnDef="Age">
<th mat-header-cell *matHeaderCellDef> Age </th>
<td mat-cell *matCellDef="let element"> {{element.Age}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table> ```
HTML Код для всплывающего окна: Компонент: 2
```<h1 mat-dialog-title>Student Details</h1>
<div style="float:left; border:solid;padding:8px;" > Class A
<table>
<tr>
<td>First Name</td>
</tr>
<tr>
<td>Last Name</td>
</tr>
<tr>
<td>Address</td>
</tr>
<tr>
<td>Contact No</td>
</tr><tr>
<td>Class</td>
</tr>
<tr>
<td>Section</td>
</tr>
<tr>
<td>Age</td>
</tr>
</table>
</div>
<div style="float:left; border:solid;padding:8px;"> Class B
<table>
<tr>
<td>First Name</td>
</tr>
<tr>
<td>Last Name</td>
</tr>
<tr>
<td>Address</td>
</tr>
<tr>
<td>Contact No</td>
</tr><tr>
<td>Class</td>
</tr>
<tr>
<td>Section</td>
</tr>
<tr>
<td>Age</td>
</tr>
</table>
</div>```
Код для открытого всплывающего окна: Компонент: 2
this.dialog.open(DialogDataExampleDialog, {
data: {
anstudentData: 'firstname'
}
});
}
}```