大佬教程收集整理的这篇文章主要介绍了Angular FIrebase 5对象键未显示.所以无法删除,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
基本firebase db:
可以看出,课程对象显然有键.
加价:
<ul> <li *ngFor="let course of courses$| async"> <b>Key:</b> {{Course.$key}} <!-- doesn't show --!> <b>title:</b> {{Course.titlE}} <b>Duration:</b> {{Course.Duration}} <b>Author:</b> {{Course.Author}} <p><button (click)="deleteCourse(coursE)">Remove</button></p> <hr> </li> </ul>
现在,这些课程显示得很好,但我不知道如何获取对该键的引用以便删除它. (或许我在firebaseDatabase对象上没有使用正确的方法).无论哪种方式,当我在控制台中记录密钥时,它显示为未定义.
export class AppComponent { courses; courses$: AngularFireList<any>; constructor(private db: AngularFireDatabasE) { this.courses = db.list('/courses'); this.courses$= this.courses.valueChanges(); } ... deleteCourse(coursE) { console.log(course.$key); // -> undefined this.db.object('/courses/' + course.$key).remove(); } }
this.courses$= this.courses.snapshotChanges().map(changes => { return changes.map(c => ({ key: c.payload.key,...c.payload.val() })); });
这是您更正后的代码
import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/map'; export class AppComponent { courseRef: AngularFireList<any>; courses$: Observable<anY[]>; constructor(private db: AngularFireDatabasE) { this.courseRef = db.list('/courses'); this.courses$= this.courseRef.snapshotChanges().map(changes => { return changes.map(c => ({ key: c.payload.key,...c.payload.val() })); }); } ... deleteCourse(coursE) { console.log(course.key); this.db.object('/courses/' + course.key).remove(); } }
以上是大佬教程为你收集整理的Angular FIrebase 5对象键未显示.所以无法删除全部内容,希望文章能够帮你解决Angular FIrebase 5对象键未显示.所以无法删除所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。