0

I am tring to retrieve a single object from firebase it doesn't return any value instear I have this message instead "FirebaseObjectObservable {_isScalar: false, $ref: Reference, source: FirebaseObjectObservable, operator: ObserveOnOperator}"

this is how I write my service , getDataList() method work perfectly.The get getDataD() which supposed to retrieve a single object is my concern.

import { Injectable } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable , FirebaseObjectObservable} from 'angularfire2/database';
import { Data } from '../data';
import { AngularFireModule } from 'angularfire2';


@Injectable()
export class Ng2fireServiceService {

  private basePath: string = '/data';
  dataL: FirebaseListObservable<Data[]> = null; //  list of objects
  dataD: FirebaseObjectObservable<Data> = null; //   single object

  constructor(private af: AngularFireModule,
              private db: AngularFireDatabase) { }


  getDataList(query={}): FirebaseListObservable<Data[]> {
  this.dataL = this.db.list(this.basePath, {
    query: query
  });
  return this.dataL
  }
// Return a single observable item
  getDataD(key: string): FirebaseObjectObservable<Data> {
    const dataPath =  `${this.basePath}/${key}`;
    this.dataD = this.db.object(dataPath)
    return this.dataD
  }

}

and this how I call it in my component

import { Ng2fireServiceService } from '../../services/ng2fire-service.service';
import { Component, OnInit} from '@angular/core';
import { Data } from '../../data';
import { Router, ActivatedRoute, Params } from '@angular/router';



@Component({
  selector: 'app-data-detail',
  templateUrl: './data-detail.component.html',
  styleUrls: ['./data-detail.component.css']
})
export class DataDetailComponent implements OnInit {

  id : string ;
  dataD : any;

  constructor( public authService :AuthService, private SVC : Ng2fireServiceService,private router : Router,
    private route : ActivatedRoute) { }

  ngOnInit() {

    this.id = this.route.snapshot.params['id'];

    this.dataD = this.SVC.getDataD(this.id);

    console.log(this.dataD);
  }

}

do you have any ideo of how to deal with this

1 Answer 1

1

Because you dont subscribe to Observable. Try this:

  ngOnInit() {

    this.id = this.route.snapshot.params['id'];

    this.SVC.getDataD(this.id).subscribe(val => this.dataD = val); 
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.