错误:路径必须是非空字符串,不能包含".","#","$","["或"]"(离子2和firebase)

Col*_*ong 4 javascript firebase firebase-realtime-database ionic2 angular

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

执行此方法后,出现错误:Firebase.child失败:第一个参数是无效路径:"request/$ {auth.uid}".路径必须是非空字符串,并且不能包含".","#","$","["或"]".尝试删除$,但这不起作用.很确定我也没有传递空字符串.

R. *_*rds 7

如果要使用字符串插值,则需要使用返回刻度(`)而不是单引号(')来包装字符串.见下文.

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

容易忘记!:)