如何从angular2 firebase数据中获取数据。

时间:2017-06-13 13:03:18

标签: javascript angular firebase firebase-realtime-database

我在angular2 firebase中有candidate_list表,但我没有从中获取值。

我的ts文件是这个

import { Component, OnInit,Input } from '@angular/core';
import { AngularFireDatabase, FirebaseListObservable, FirebaseObjectObservable } from 'angularfire2/database';
import * as firebase from 'firebase';
import { FirebseService } from "app/firebse.service";

@Component({
  selector: 'app-candidate-reg-complete',
  templateUrl: './candidate-reg-complete.component.html',
  styleUrls: ['./candidate-reg-complete.component.css']
})
export class CandidateRegCompleteComponent implements OnInit {
  content:any;
item: FirebaseObjectObservable<any>;
  constructor(private db: AngularFireDatabase,
  private firebaseService:FirebseService) { 
    this.item = db.object('candidates_list');
  }

  ngOnInit() {
  }
  upload(documents){

  //  let file=user.files[0];
  //   console.log(file);
  //  console.log(file.name);
  let storageRef=firebase.storage().ref();

    for(let selectedFile of[(<HTMLInputElement>document.getElementById('file')).files[0]]){

     let path='/resumes/'+selectedFile.name;
      let iRef=storageRef.child(path);
      iRef.put(selectedFile).then((snapshot)=>{
        debugger;
       documents.resume=selectedFile.name;
       documents.path=path;

        var Userid=localStorage.getItem('user');
        console.log(documents);
        let content=this.db.object('/candidates_list/'+Userid);
        console.log(content);

        // this.db.object('/candidates_list/'+Userid).update(documents);
      localStorage.setItem('resume',documents.path);

      })
 }

}
}

问题在于此代码

 let content=this.db.object('/candidates_list/'+Userid);
 console.log(content);

当我尝试控制此值时,输出就像这样..

FirebaseObjectObservable {_isScalar: false, $ref: U, source: FirebaseObjectObservable, operator: ObserveOnOperator}

不支持确切的内容,所以解决这个问题的方法是什么?

1 个答案:

答案 0 :(得分:0)

您需要订阅observable。试试这个:

 let content = this.db.object('/candidates_list/'+Userid)
  content.subscribe(data => {
    console.log(data)})