-1

my .ts file is this

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)
            content.subscribe(data => {
              this.data=this.data.concat(documents);
              this.db.object('/candidates_list/'+Userid).set(this.data);
            console.log(this.idcontent=data);

       })

it shows that error core.es5.js:1084 ERROR TypeError: Cannot read property 'concat' of undefined. how to solve this problem?thanks in advance.the problem is with this code.

this.data=this.data.concat(documents);

thanks in advance

AL.
  • 36,815
  • 10
  • 142
  • 281
pranavyoyo
  • 75
  • 1
  • 6

1 Answers1

1

try

this.data= data.concat(documents);

the problem is you are concatenating this.data that is undefined because only now you are defining it. I guess its a typo?

Yonatan Lilling
  • 298
  • 1
  • 4
  • 13
  • sir when i use this code it is showing data.concat is not a function error.How can it be solved.please help me? – pranavyoyo Jun 14 '17 at 12:22
  • what do you get in `data`? – Yonatan Lilling Jun 14 '17 at 12:25
  • when i am subscribing i am getting data as the current content from the specified key.After that i want to add the documents (path&name of the file i am uploaded).Thats why i concat(),These two.But concat is the problem.i have also declared data:any.any other option to concatenate two json objects from firebase to a single object. – pranavyoyo Jun 14 '17 at 12:31
  • what about [this](https://stackoverflow.com/questions/2454295/how-to-concatenate-properties-from-multiple-javascript-objects)? It uses Object.assign() – Yonatan Lilling Jun 14 '17 at 13:27
  • should i use like this this.data=Object.assign(data,documents); – pranavyoyo Jun 14 '17 at 13:33
  • so check it as answered :) – Yonatan Lilling Jun 15 '17 at 13:37