我正在尝试在用户身份验证后将用户输入发送到firebase。我正在使用Ionicframework。这就是我的尝试。
错误未被捕获(在承诺中):错误:Reference.child失败:第一个参数是无效路径='profile / $ {auth.uid}'。
打字稿文件:
import { Component,ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import {AngularFireAuth} from 'angularfire2/auth';
import {AngularFireDatabase} from 'angularfire2/database';
import { TabsPage } from '../tabs/tabs';
/**
* Generated class for the FpPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
@IonicPage()
@Component({
selector: 'page-fp',
templateUrl: 'fp.html',
})
export class FpPage {
@ViewChild('uname') uname;
constructor(private fire:AngularFireAuth,private db :AngularFireDatabase,public navCtrl: NavController, public navParams: NavParams) {
}
createProfile(){
this.fire.authState.take(1).subscribe(auth => {
this.db.list('profile/${auth.uid}').push(this.uname)
.then(() => this.navCtrl.push('TabsPage'))
})
}
ionViewDidLoad() {
console.log('ionViewDidLoad FpPage');
}
}
HTML:
<ion-content padding>
<ion-item>
<ion-label floating>Username</ion-label>
<ion-input type="username" #uname></ion-input>
</ion-item>
<button ion-button clear block (click)="createProfile()">Set Username</button>
</ion-content>
答案 0 :(得分:0)
您的代码中存在错误。您正在尝试使用与`一起使用的模板文字,并允许您使用字符串参数,但您使用的是常见的字符串字符(&#39;&#39;)。
要解决您的代码,您应该更改代码:
this.db.list('profile/${auth.uid}').push(this.uname)
为:
this.db.list(`profile/${auth.uid}`).push(this.uname)
有关模板文字的更多文档,请查看MDN Template Literals