【问题标题】:Ionic Firebase Database cardIonic Firebase 数据库卡
【发布时间】:2020-05-05 04:33:05
【问题描述】:

我想添加带有 firebase 数据库的卡片。我的代码:

//home.page.ts
loadTinderCards() {
    this.cards = [
      {
        img: "https://placeimg.com/300/300/nature",
        title: "Demo card 1",
        description: "This is a demo cards"
      },
    ]
  };

我不想把每张卡片一张一张地写下来。

//home.page.html
<ion-content>

  <ion-refresher slot="fixed" (ionRefresh)="loadTinderCards()">
    <ion-refresher-content></ion-refresher-content>
  </ion-refresher>

  <tinder-ui [cards]="cards" (choiceMade)="logChoice($event)"></tinder-ui>


</ion-content>

【问题讨论】:

  • 我想通过我的addpage添加卡片。
  • 我想从我的“添加”页面添加一些信息(文本或图片)。所有这些信息都会出现在我的“首页”上。

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


【解决方案1】:

我有一个添加页面。

//add.page.html
<ion-content>
  <div class="header">
    <div class="title">Add</div>
  </div>

  <ion-item>
    <ion-label><b>Publiez quelque chose</b></ion-label>
  </ion-item>
  <ion-item>
    <ion-label>Titre:</ion-label>
    <ion-input type="text" [(ngModel)]="postData.title"></ion-input>
  </ion-item>
  <ion-item>
    <ion-label>Texte:</ion-label>
    <ion-input type="text" [(ngModel)]="postData.text"></ion-input>
  </ion-item>
  <ion-item>
    <ion-label>Url de l'image:</ion-label>
    <ion-input type="text" [(ngModel)]="postData.imgUrl"></ion-input>
  </ion-item>
  <ion-button expand="block" (click)="publish()">Publier</ion-button>

</ion-content>

用于在我的数据库中发送数据。

//add.page.ts
export class AddPage {
  postData = {
    text: '',
    imgUrl: '',
    title: ''
  };

  constructor(public router:Router,  public afDB: AngularFireDatabase,
    public afAuth: AngularFireAuth) {}


  publish() {
    this.afDB.list('Posts/').push({
       text: this.postData.text,
       imgUrl: this.postData.imgUrl,
       title: this.postData.title,
       likesNb: 0
    });
    this.postData = {
      title:'',
      text: '',
      imgUrl: ''
  };
 }

}

【讨论】:

  • 您的问题在哪里?是在firebase中插入还是在html绑定方式中还是在整个过程中??
猜你喜欢
  • 1970-01-01
  • 2019-04-08
  • 1970-01-01
  • 2017-10-31
  • 1970-01-01
  • 2021-06-03
  • 2018-11-19
  • 1970-01-01
  • 2019-08-10
相关资源
最近更新 更多