简体   繁体   English

ionic firestore提交数据

[英]ionic firestore submit data

I am trying to submit some data in firestore but its showing me error. 我正在尝试在Firestore中提交一些数据,但显示给我错误。

FirebaseError: Function CollectionReference.doc() requires its first argument to be of type string, but it was: undefined.

installment.html installment.html

<ion-content>
  <div [ngSwitch]="galleryType">
    <ion-card *ngSwitchCase="'Form'">
      <ion-item>
        <ion-label floating>Name</ion-label>
        <ion-input type="text" [(ngModel)]="name">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Address</ion-label>
        <ion-input type="text" [(ngModel)]="address">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>CNIC</ion-label>
        <ion-input type="number" [(ngModel)]="cnic">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Email</ion-label>
        <ion-input type="email" [(ngModel)]="email">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Phone number </ion-label>
        <ion-input type="number" pattern="^([+]92[0-9]{10}|[0-9]{11})$" [(ngModel)]="number">
        </ion-input>
      </ion-item>
      <br>
      <ion-item>
        <ion-label>City</ion-label>
        <ion-select [(ngModel)]="city">
          <ion-option value="karachi">Karachi</ion-option>
          <ion-option value="Lahore">Lahore</ion-option>
          <ion-option value="Multan">Multan</ion-option>
          <ion-option value="islamabad">Islamabad</ion-option>
        </ion-select>
      </ion-item>
      <ion-item>
        <ion-label floating>Profession</ion-label>
        <ion-input type="text" [(ngModel)]="profession">
        </ion-input>
      </ion-item>
      <br>
      <ion-item>
        <ion-label >Select a Bank</ion-label>
        <ion-select [(ngModel)]="bank">
          <ion-option value="HBL">HBL</ion-option>
          <ion-option value="Al Habib">Al Habib</ion-option>
          <ion-option value="SCB">SCB</ion-option>
          <ion-option value="BI">Bank Islami</ion-option>
        </ion-select>
      </ion-item>
      <button style="display:block;margin: 16px auto;" ion-button no-padding (click)="gotoDate()"><img class="tick" src="assets/image/tick.png"></button>
    </ion-card>
    <ion-card *ngSwitchCase="'Date'">
      <ion-item>
        <ion-label floating>Guarantor 1 Name </ion-label>
        <ion-input type="text" [(ngModel)]="g1name" >
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Phone number </ion-label>
        <ion-input type="number" pattern="^([+]92[0-9]{10}|[0-9]{11})$" [(ngModel)]="g1number">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Address </ion-label>
        <ion-input type="text" [(ngModel)]="g1address">
        </ion-input>
      </ion-item>
      <br>
      <ion-item>
        <ion-label>City</ion-label>
        <ion-select [(ngModel)]="g1city">
          <ion-option value="karachi">Karachi</ion-option>
          <ion-option value="lahore">Lahore</ion-option>
          <ion-option value="multan">Multan</ion-option>
          <ion-option value="islamabad">Islamabad</ion-option>
        </ion-select>
      </ion-item>
      <br>
      <ion-item>
        <ion-label floating>Guarantor 2 Name </ion-label>
        <ion-input type="text" [(ngModel)]="g2name">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Phone number </ion-label>
        <ion-input type="text" pattern="^([+]92[0-9]{10}|[0-9]{11})$" [(ngModel)]="g2number">
        </ion-input>
      </ion-item>
      <ion-item>
        <ion-label floating>Address </ion-label>
        <ion-input type="text"[(ngModel)]="g2address" >
        </ion-input>
      </ion-item>
      <br>
      <ion-item>
        <ion-label>City</ion-label>
        <ion-select [(ngModel)]="g2city">
          <ion-option value="karachi">Karachi</ion-option>
          <ion-option value="lahore">Lahore</ion-option>
          <ion-option value="multan">Multan</ion-option>
          <ion-option value="islamabad">Islamabad</ion-option>
        </ion-select>
      </ion-item>
      <button style="display:block;margin: 16px auto;" ion-button no-padding><img class="tick" src="assets/image/tick.png" (click)="submit(name, address, cnic, email, number, city, profession, bank, g1name, g1number, g1address, g1city, g2name, g2address, g2number, g2city) "></button>
    </ion-card>
  </div>
</ion-content>

.ts .ts

submit(name, address, cnic, email, number, city, profession, bank, g1name,
  g1number, g1address, g1city, g2name, g2address, g2number, g2city) {
  if (this.name == "") {
    console.log('empty');
    return;
  } else {
    let deal = {
      name: this.name,
      address: this.address,
      cnic: this.cnic,
      email: this.email,
      number: this.number,
      city: this.city,
      profession: this.profession,
      bank: this.bank,
      // Guarantor1name: this.g1name,
      g1number: this.g1number,
      g1address: this.g1address,
      g1city: this.g1city,
      //Guarantor2name: this.g2name,
      g2number: this.g2number,
      g2address: this.g2address,
      g2city: this.g2city,
    }

    this.afs.collection('installment').doc().set(deal);
    let alert = this.alertCtrl.create({
      title: "ATTENTION",
      subTitle: "Done",
      buttons: ['OK']
    });
    alert.present();
  }
}

I need to send the data to firestore. 我需要将数据发送到Firestore。 Any one can please tell me how can I send it? 谁能告诉我如何发送?

Looks like you are trying to create a new document, but currently, your code doesn't set a document id to be created. 看起来您正在尝试创建一个新文档,但是当前,您的代码未设置要创建的文档ID。 One suggestion is to just let Cloud Firestore use an auto id. 一个建议是让Cloud Firestore使用自动ID。

To do this change this line: 为此,请更改此行:

this.afs.collection('installment').doc().set(deal);

To this: 对此:

this.afs.collection('installment').add(deal);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Firestore获取数据并放入Ionic中的数组 - Get data from firestore and put into array in Ionic 使用Cloud Firestore的Ionic App-查看所有用户的数据 - Ionic App using Cloud Firestore - See data for all users 如何使用 Cloud Firestore 在 ionic 4 应用程序中获取数据 - How to use cloud firestore to get data in an ionic 4 app 我想通过单击按钮将数据提交到 Cloud Firestore 文档 - I want to submit data to cloud firestore document onclick of a button 当我通过表单输入数据并提交时,firebase 获得了图像,但其他数据的详细信息没有出现在 Firestore collections - While I enter data through a form and submit , firebase gets the image but details of other data didn't get on the firestore collections Ionic firestore如何检查firestore中是否存在文档ID - Ionic firestore how to check document id exist in firestore or not 从 Firestore 获取记录进行分页 - Ionic/Angular - Fetch records from Firestore for pagination - Ionic/Angular 如何使用Firestore处理Ionic 4上的过滤器搜索栏? - How to deal with the filter searchbar on Ionic 4 with Firestore? Ionic 3将Facebook用户保存到Firestore数据库 - Ionic 3 save facebook user to firestore database AngularFire2 / Firestore存储-getDownloadURL()(离子) - AngularFire2 / Firestore Storage - getDownloadURL() (Ionic)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM