Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何在角垫桌上放置不同的按钮?_Arrays_Angular_Button_Angular Material - Fatal编程技术网

Arrays 如何在角垫桌上放置不同的按钮?

Arrays 如何在角垫桌上放置不同的按钮?,arrays,angular,button,angular-material,Arrays,Angular,Button,Angular Material,我使用angular mat table显示一组数据,如下所示,并进行简单排序。最后一列是一列按钮。我希望在每一行中都有不同的按钮,可以路由到不同的组件 如何在每行中添加使用routerLink路由到不同组件的不同按钮。是否要将每个链接重定向到不同的角度组件,还是要将每个链接重定向到相同的角度组件(例如,设备详细信息组件),但url和设备信息不同(如重定向到“/device/1”、“device/2”等) 如果是后者,则假设您希望将每个设备重定向到角度路由“/device detail/:id

我使用angular mat table显示一组数据,如下所示,并进行简单排序。最后一列是一列按钮。我希望在每一行中都有不同的按钮,可以路由到不同的组件


如何在每行中添加使用routerLink路由到不同组件的不同按钮。

是否要将每个链接重定向到不同的角度组件,还是要将每个链接重定向到相同的角度组件(例如,设备详细信息组件),但url和设备信息不同(如重定向到“/device/1”、“device/2”等)

如果是后者,则假设您希望将每个设备重定向到角度路由“/device detail/:id”,其中id是设备的标识。为简单起见,假设id是序列号。因此您只需更改按钮声明。将
[routerLink]=”替换为
[routerLink]=['/device detail',device.serialNo]“
(我还将
*matCellDef=“let row”
更改为
*matCellDef=“let device”
):


看法

是的,这正是我想要做的。谢谢你的帮助!
  <!-- Name Column -->
  <ng-container matColumnDef="name">
    <th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
    <td mat-cell *matCellDef="let device"> {{device.name}} </td>
  </ng-container>

  <!-- SerialNo Column -->
  <ng-container matColumnDef="serialNo">
    <th mat-header-cell *matHeaderCellDef > SerialNo </th>
    <td mat-cell *matCellDef="let device"> {{device.serialNo}} </td>
  </ng-container>

<!-- Button Column -->
  <ng-container matColumnDef="actions">
    <th mat-header-cell  *matHeaderCellDef > Actions </th>
    <td mat-cell *matCellDef="let row" >
      <button mat-button routerLinkActive="list-item-active" routerLink="/device1" >View</button>
    </td>
export interface Devices {
  name: string;
  position: number;
  serialNo: number;
}
//An Array of device1
const DEVICES: Devices[] = [
  {position: 1, name: 'Device 1', serialNo: 135421},
  {position: 2, name: 'Device 2', serialNo: 125240},
  {position: 3, name: 'Device 3', serialNo: 124350},
  {position: 4, name: 'Device 4', serialNo: 124500},
  {position: 5, name: 'Device 5', serialNo: 145620},
];

  displayedColumns: string[] = ['position', 'name', 'serialNo', 'actions'];
  dataSource = new MatTableDataSource(DEVICES);

  @ViewChild(MatSort) sort: MatSort;

  ngAfterViewInit() {
    this.dataSource.sort = this.sort;
  }