Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]" (ionic 2 and firebase) [closed]

saveDetails(){
  this.afAuth.authState.take(1).subscribe(auth => {
    this.af.object('request/${auth.uid}').set(this.request)
    .then();
  })

After executing this method, an error: Firebase.child failed: First argument was an invalid path: "request/${auth.uid}". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]" is being shown. Tried removing $ but that doesn't work. Pretty sure i am not passing in empty strings too.

like image 416
Colin Wong Avatar asked Jul 08 '17 17:07

Colin Wong


2 Answers

If you are going to use string interpolation, you need to use back ticks (`), and not single quotes ('), to wrap a string. See below.

saveDetails(){
  this.afAuth.authState.take(1).subscribe(auth => {
    this.af.object(`request/${auth.uid}`).set(this.request)
    .then();
  })

Easy one to forget! :)

like image 93
R. Richards Avatar answered Oct 23 '22 17:10

R. Richards


The correct way to use your variable in this context is this

saveDetails(){
  this.afAuth.authState.take(1).subscribe(auth => {
    this.af.object('request/'+ auth.uid).set(this.request)
    .then();
  })
like image 33
Emeka Obianom Avatar answered Oct 23 '22 16:10

Emeka Obianom