0

Below is my screenshot database:

enter image description here

I want to get single course - by id, here is my code:

Service:

 getSingle(uid: string) {
    return this.db
      .object(`courses/${uid}`)
      .snapshotChanges()
      .pipe(map(res => res.payload.val()));
  }

Component:

ngOnInit() {
    this.coursesService.getSingle('Kyric46r714Kibjqw2E').subscribe(item => {
      console.log(item);
    });

i am getting null - in console.log(item)

Moreover, if i change my service to this:

 getSingle(uid: string) {
    return this.db
      .object(`courses/${uid}`)
      .snapshotChanges()
      .pipe(map(res => res.payload.key)); < ------------
  }

i am getting in console.log(item) my key - Kyric46r714Kibjqw2E, as i should.

why the val() method doesn't work?

Thanks for help in advance!!!

1 Answer 1

2

You need to add the dash - next to you id to retrieve the data inside of it:

this.coursesService.getSingle('-Kyric46r714Kibjqw2E').subscribe(item
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.