如何使用角度/打字稿从消防站获取随机物品

时间:2019-03-17 20:18:46

标签: angular typescript firebase google-cloud-firestore

我正在制作一个测验应用程序,我只想从消防站里拿一个随机物品。我已经制作了随机数生成器,但是我不知道如何从这里继续。

打字稿:

import { Injectable } from '@angular/core';

import { AngularFirestore } from '@angular/fire/firestore';

@Injectable({
  providedIn: 'root'
})
export class CrudService {

  constructor(
    private firestore: AngularFirestore
  ) { }


  create_NewQuiz(record) {
    return this.firestore.collection('Quizzes').add(record);
  }

  read_Quizzes() {
    let numberOfQuestion = 5;
    let randomQuestion = Math.floor(Math.random() * numberOfQuestion);

    return this.firestore.collection('Quizzes').snapshotChanges();
  }

  update_Quiz(recordID,record){
    this.firestore.doc('Quizzes/' + recordID).update(record);
  }

  delete_Quiz(record_id) {
    this.firestore.doc('Quizzes/' + record_id).delete();
  }
}

0 个答案:

没有答案
相关问题