angular - 无法从 firebase-Angular http://localhost:4200/admin/products/undefined 获取 $key
问题描述
我在学习课程的同时从事 Angular 项目。我正在尝试从我的 Firebase 中获取 $key,并在路由中使用它来重定向到编辑页面,但我不断收到“未定义”。我从这里尝试了多种解决方案,但没有任何效果。
我的产品服务。
create (product) {
return this.db.list('/products').push(product);
}
getAll() {
return this.db.list('/products').valueChanges();
}
get(productId) : Observable<any> { return this.db.object('/products/' + productId).snapshotChanges();
}
我想在哪里使用 $key。
<a [routerLink]="['/admin/products/',p.$key]"> Edit </a>
我在浏览器中得到的:http://localhost:4200/admin/products/undefined
解决方案
your best bet would be to try as an example like so - set your variable from firebase or firestore as products in your yourcomponent.component.html file:
<div *ngFor="let item of products | keyvalue">
<a [routerLink]="['/admin/products/',item.key]"> Edit </a>
</div>
keyvalue 管道由 angular 专门用于分段值和键,并且与 ngfor 配合得很好。
推荐阅读
- database - mongodb没有名为restore的角色
- php - PHP 文件不会从 HTML 按钮运行,而是会自行运行
- java - Java groupingBy:对多个字段求和
- swift - 安装 Onesignal Cocoapod
- node.js - 在带有 ES 模块的 Node.js 中使用相对路径导入
- javascript - const 并且 let 不能在 Safari 9.x 中工作,这是一个转译器问题吗?
- probability - 如何计算涉及多个变量的联合概率?
- typescript - 在 TypeScript 中,如何自动将对象属性分配给我的类?
- php - 为什么我的 PHP 错误出现在几个不同的文件中?
- python - Python 脚本返回 Schema XML 请求错误 SimpleDeserializer