简体   繁体   中英

How to update the angular2 firebase database?

I have candidates_list table in firebase database. It contains different parameters like name ,city,skill etc. These all parameters I have submitted through one form. After submitting the form the page is redirect to next page where we want submit his resume. I don't know how to update the candidates_list with resume name and path.

My .html file is below

<div class="container">
  <div class="row">
        <div class="col-md-3">
        </div>
    <div class="col-md-6">
          <div class="jumbotron">

          <h2>Complete your Profile</h2>
          <h5 style="color:royalblue;">Add your updated Resume to get notified by Recruiters</h5>
          <form>
            <label>Resume</label>
          <input id="file" name="file" type="file" #fileinput ><br>

          <button (click)="upload(fileinput)" type="button" class="btn btn-success">Submit</button>
        </form>




          </div>
    </div>
  </div>
</div>

My .ts page is

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 {
item: FirebaseObjectObservable<any>;
  constructor(private db: AngularFireDatabase,
  private firebaseService:FirebseService) { 
    this.item = db.object('candidates_list');
  }

  ngOnInit() {
  }
  upload(documents){
    debugger;
  //  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)=>{

       documents.resume=selectedFile.name;
       documents.path=path;
        var Userid=localStorage.getItem('user');
        console.log(documents);
        this.db.object('/candidates_list/'+Userid).update(documents);
      localStorage.setItem('resume',documents.path);

      })
 }

}
}


var Userid=localStorage.getItem('user');

Here I mean to take the UID of the user which has set into local storage while logging in. How to solve this problem. Any solution? Please help me. Thanks in advance

Upload the resume file to firebase storage refer this article firebase storage If the file is uploaded successfully ,the callback will return a snapshot object , you will get the uploaded file details there. And then you can make a request to update the firebase database with these file details from the snapshot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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