【问题标题】:Angular 8 - Routing not happend - Mat table rowAngular 8 - 路由未发生 - 垫表行
【发布时间】:2020-04-04 09:30:28
【问题描述】:

我不知道为什么点击行后我的路由没有发生。 没有错误显示。 URL 中的路径从“http://localhost:4200/vendor-list”更改为“http://localhost:4200/vendor-list/vendor” 但是页面没有变化。

vendorlist.component.html

<tr mat-header-row *matHeaderRowDef="ordersDisplayedColumns"></tr>
<tr (click)="displayData(row)" mat-row *matRowDef="let row; columns: ordersDisplayedColumns;"></tr>
</table>

vendorlist.component.ts

displayData(row)
  {
    console.log(row);
    this.router.navigate(["/vendor-list/vendor/"]);
  }

myrouting.module.ts

{path:'vendor-list',component:VendorlistComponent,
children:[
  {path:'vendor',component:VendorComponent, 
]},

【问题讨论】:

标签: angular typescript angular-routing


【解决方案1】:
{path:'vendor-list',
 children:[
   {path:'vendor',component:VendorListComponent,canActivate:[AuthguardGuard]},
   {path:'vendor',component:VendorComponent,canActivate:[AuthguardGuard]}

 ]}

请检查这个

【讨论】:

    【解决方案2】:

    使用 url 参数路由到每行的唯一 ID。

    vendorlist.component.html

        <tr mat-header-row *matHeaderRowDef="ordersDisplayedColumns"></tr>
    <tr (click)="displayData(row, i)" mat-row *matRowDef="let row; let index as i; columns: ordersDisplayedColumns;"></tr>
    </table>
    

    vendorlist.component.ts

    displayData(row, id)
      {
        console.log(row);
        this.router.navigate([`/vendor-list/vendor/${id}`]);
      }
    

    myrouting.module.ts

        {path:'vendor-list',component:VendorlistComponent,
    children:[
      {path:'vendor/:id',component:VendorComponent, 
    ]},
    

    【讨论】:

    • 模板解析错误:无法绑定到“matRowDefAs”,因为它不是“tr”的已知属性。 ("ow *matHeaderRowDef="ordersDisplayedColumns">
    • 在上下文中检查模块中的导入。你导入 MatTable 模块了吗?
    猜你喜欢
    • 2019-09-11
    • 2020-02-25
    • 2020-05-24
    • 2020-01-15
    • 1970-01-01
    • 2021-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多