javascript - 动态 routeLink 无法显示 URL
问题描述
<table class="table">
<thead>
<tr>
<th>Title</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<tr *ngFor= "let p of products$ | async ">
<td>{{p.title}}</td>
<td>{{p.price}}</td>
<td>
<a [routerLink] = "['/admin/products/', p.key]" >Edit</a>
</td>
</tr>
</tbody>
</table>
{
path: 'admin/products',
component: AdminProductsComponent,
canActivate: [AuthGuard, AdminAuthGuard]
},
{
path: 'admin/products/new',
component: ProductFormComponent,
canActivate: [AuthGuard, AdminAuthGuard]
},
{
**path: 'admin/products/:id',**
component: ProductFormComponent,
canActivate: [AuthGuard, AdminAuthGuard]
},
你好朋友!
您可以在图片中看到下面的蓝色单词“编辑”。我希望它显示 amdin/product + 'URl' ,但结果是 admin/product/undefined。
而且我在上面给出了我为此功能目的编写的代码,我的问题在哪里????
此外,我在 cmd 和 chrome 控制台中都没有遇到任何兼容错误。
问候!
解决方案
在您使用的编辑链接中p.key
,如下所示,
<a [routerLink] = "['/admin/products/', p.key]" >Edit</a>
但是在产品数组中,您没有获得该数组对象中的key
字段。product
所以p.key
将是未定义的
推荐阅读
- progress-bar - 4 名玩家的进度条
- android - 在 api 30 中返回 false BindService
- c# - 如何在用户 pc 上创建本地 postgresql 数据库
- laravel - 如何在 Laravel 中使用 spatie 权限中间件?
- java - Android Studio BackgroundService 在没有用户交互的情况下一直运行?
- java - 如何在spring中创建自定义查询方法生成器
- javascript - HTML输入元素在EJS中使用电子返回空格
- bash - 如何在蛇形规则中使用 bash for 循环
- python - heroku 电报机器人,BadRequest:Bad webhook:保留 IP 地址 0.0.0.0
- python - 如何在python中做一个堆栈图,按一个类别按百分比排序?