ionic firebase:Reference.child失败:第一个参数是无效路径=“ undefined”。路径必须是非空字符串,并且不能包含

时间:2018-10-08 17:46:53

标签: javascript angularjs firebase ionic-framework firebase-realtime-database

我正在尝试通过身份验证在Firebase中添加一些数据,并通过注册表单来添加数据库。我正在使用离子来执行此插入。按下注册按钮后,数据的身份验证方面可以很好地进入身份验证存储。但是,在存储其他数据时出现此错误。

我已经尝试了所有可能的方法,并且搜索解决方案似乎无济于事

下面是我的register.html代码

<ion-content padding>
<ion-list>

    <ion-item>
      <!--ion-label fixed>Username</ion-label-->
      <ion-input type="text" [(ngModel)]="fullname" name="fullname" placeholder="Fullname"></ion-input>
    </ion-item>

      <ion-item>
      <!--ion-label fixed>Mobile Number</ion-label-->
      <ion-input type="tel" [(ngModel)]="mobilenumber" name="mobilenumber" placeholder="Mobile Number"></ion-input>
    </ion-item>

      <ion-item>
      <!--ion-label fixed>Email</ion-label-->
      <ion-input type="email" [(ngModel)]="email" name="email" placeholder="Email Add. Eg. ola@olasam.com"></ion-input>
    </ion-item>

    <ion-item>
      <!--ion-label fixed>Username</ion-label-->
      <ion-input type="text" [(ngModel)]="username" name="username" placeholder="Username"></ion-input>
    </ion-item>

    <ion-item>
      <!--ion-label fixed>Password</ion-label-->
      <ion-input type="password" [(ngModel)]="password" name="password" placeholder="Password"></ion-input>
    </ion-item>

    <ion-item>
    <ion-label>Gender</ion-label>
    <ion-select [(ngModel)]="gender" name="gender">
      <ion-option value="female">Female</ion-option>
      <ion-option value="male">Male</ion-option>
    </ion-select>
  </ion-item>

  <ion-item>
    <ion-label>Occupation</ion-label>
    <ion-select [(ngModel)]="occupation" name="occupation">
      <ion-option value="student">Student</ion-option>
      <ion-option value="driver">Driver</ion-option>
      <ion-option value="medical officer">Medical Officer</ion-option>
      <ion-option value="software developer">Software Developer</ion-option>
      <ion-option value="farmer">Farmer</ion-option>
      <ion-option value="Academic">Academic</ion-option>
      <ion-option value="Trader">Trader</ion-option>
    </ion-select>
  </ion-item>

  <ion-item>
    <ion-label>Drug Status</ion-label>
    <ion-select [(ngModel)]="drugstatus" name="drugstatus">
      <ion-option value="Clean">Clean</ion-option>
      <ion-option value="Need Help">Need Help</ion-option>
    </ion-select>
  </ion-item>

  <div padding text-center>
      <button ion-button color="danger" round (click)="registerUser()" >Register</button>
  </div>     
  </ion-list>

我的register.ts代码

@IonicPage()
@Component({
  selector: 'page-register',
  templateUrl: 'register.html',
  providers: [UsersserviceProvider]
})
export class RegisterPage {

  public fullname : any;
  public mobilenumber : any;
  public email : any;
  public username : any;
  public password : any;
  public gender : any;
  public occupation : any;
  public drugstatus : any;

  constructor(public navCtrl: NavController, public navParams: NavParams, public usersserviceProvider : UsersserviceProvider, 
    public toastCtrl: ToastController, public loadingCtrl: LoadingController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RegisterPage');
  }

  registerUser() {

    var account = {
      fullname: this.fullname,
      mobilenumber: this.mobilenumber,
      email: this.email,
      username: this.username,
      password: this.password,
      gender: this.gender,
      occupation: this.occupation,
      drugstatus: this.drugstatus

    };

    var that = this;

    var loader = this.loadingCtrl.create({
      content: "Please wait...",

    });
    loader.present();

    this.usersserviceProvider.registerUserService(account).then(authData => {
        //successful
        loader.dismiss();
        that.navCtrl.setRoot(HomePage);

    }, error => {
loader.dismiss();
     // Unable to log in
      let toast = this.toastCtrl.create({
        message: error,
        duration: 3000,
        position: 'top'
      });
      toast.present();

      that.password = ""//empty the password field

    });

  }

}

下面是usersservice.ts提供程序

@Injectable()
export class UsersserviceProvider {

  public data: any;
  public fireAuth: any;
  public userProfile: any;

  constructor(public http: Http) {
    this.fireAuth = firebase.auth();
    this.userProfile = firebase.database().ref('users'); //This is where we are storing the rest of the users data. Email and password are stored in a different place which is called Authentication
  }

  loginUserService(email: string, password: string): any {
    return this.fireAuth.signInWithEmailAndPassword(email, password);
  }

  registerUserService(account: {}){


    return this.fireAuth.createUserWithEmailAndPassword(account['email'], account['password']).then((newUser) => {
      //sign in the user
      this.fireAuth.signInWithEmailAndPassword(account['email'], account['password']).then((authenticatedUser) => {
        //successful login, create user profile
      this.userProfile.child(authenticatedUser.uid).set(account);
      });
    });

}


}

我得到的错误的堆栈跟踪在下面,并且不清楚。

enter image description here

感谢您的协助。

0 个答案:

没有答案