简体   繁体   English

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

[英]How to take the data from the angular2 firebase data.?

I have candidates_list table in angular2 firebase, but I am not getting the value from it. 我在angular2 firebase中有候选人列表表,但是我没有从中获得价值。

My ts file is this 我的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);

      })
 }

}
}

The problem is with this code 问题是此代码

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

When I try to console this value, the output is like this.. 当我尝试控制此值时,输出如下所示。

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

Not conoling the exact content, so any solution for this problem? 没有正确的内容,那么这个问题有什么解决方案吗?

You need to subscribe to the observable. 您需要订阅可观察的。 Try this: 尝试这个:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM