使用nodejs在Firestore云中发送角形数据

时间:2019-07-11 09:30:53

标签: node.js angular google-cloud-functions

我有一个专门为前端构建的角度应用程序,其中Akveo / ngx-admin用作构建前端的模板。现在,我有一个包含多个字段和复选框的表单,我想将该表单数据发送到Firestore云中,但后端是使用nodejs云函数创建的。所以我想用表单数据作为参数调用nodejs内部的函数,并将该数据添加到firestore中。我是Firebase云功能的初学者,所以我真的很喜欢一个解释或一点点代码帮助

scheduleclass.component。 html

<div class="row">
  <div class="col-md-12">
    <nb-card>
      <nb-card-header>Schedule a Class</nb-card-header>
      <nb-card-body>
        <form class="form-horizontal">
          <div class="form-group row">
            <label for="inputEmail3" class="label col-sm-3 form-control-label">Course</label>
            <div class="col-sm-6">
              <nb-select selected="1">
                <nb-option value="1">Choose an option</nb-option>
                <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                <nb-option value="3">Option 2</nb-option>
              </nb-select>
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Client</label>
            <div class="col-sm-6">
              <nb-select selected="1">
                <nb-option value="1">Choose an option</nb-option>
                <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                <nb-option value="3">Option 2</nb-option>
              </nb-select>
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Location</label>
            <div class="col-sm-6">
              <nb-select selected="1">
                <nb-option value="1">Choose an option</nb-option>
                <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                <nb-option value="3">Option 2</nb-option>
              </nb-select>
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Instructor</label>
            <div class="col-sm-6">
              <nb-select selected="1">
                <nb-option value="1">Choose an option</nb-option>
                <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                <nb-option value="3">Option 2</nb-option>
              </nb-select>
              <nb-checkbox style="margin-left: 10px;">Open for Bidding</nb-checkbox>
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Class Times</label>
            <div class="col-sm-6">
              <!-- <input type="text" nbInput fullWidth id="inputPassword3" placeholder="Times">
              <nb-select selected="1">
                <nb-option value="1">Choose an option</nb-option>
                <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                <nb-option value="3">Option 2</nb-option>
              </nb-select> -->
              <ng2-smart-table [settings]="settings" [source]="source" (deleteConfirm)="onDeleteConfirm($event)">
              </ng2-smart-table>
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Price</label>
            <div class="col-sm-6">
              <input type="text" nbInput fullWidth id="inputPassword3" placeholder="Price">
            </div>
          </div>
          <div class="form-group row">
            <label for="inputPassword3" class="label col-sm-3 form-control-label">Total Hours</label>
            <div class="col-sm-6">
              <input type="text" nbInput fullWidth id="inputPassword3" placeholder="Total Hours">
            </div>
          </div>
            <div class="form-group row">
              <label for="inputPassword3" class="label col-sm-3 form-control-label">Max Students</label>
              <div class="col-sm-6">
                <input type="text" nbInput fullWidth id="inputPassword3" placeholder="Max Students">
              </div>
            </div>
            <div class="form-group row">
              <label for="inputEmail3" class="label col-sm-3 form-control-label">Listing</label>
              <nb-checkbox style="margin-left: 13px;"></nb-checkbox>
            </div>
            <div class="form-group row">
              <label for="inputPassword3" class="label col-sm-3 form-control-label">Close Registration ? Days Before Class Start Date</label>
              <div class="col-sm-3">
                <input type="text" nbInput fullWidth id="inputPassword3" placeholder="Days">
              </div>
            </div>
            <div class="form-group row">
              <label for="inputPassword3" class="label col-sm-3 form-control-label">Assistants</label>
              <div class="col-sm-6">
                <nb-select selected="1">
                  <nb-option value="1">Choose an option</nb-option>
                  <nb-option value="2">hjsdjfiu bsifsl nnsflsnf fshls</nb-option>
                  <nb-option value="3">Option 2</nb-option>
                </nb-select>
              </div>
            </div>
            <div class="form-group row">
              <label for="inputPassword3" class="label col-sm-3 form-control-label">Public Notes</label>
              <div class="col-sm-6">
                <textarea rows="5" nbInput fullWidth shape="round"  placeholder="Public Notes"></textarea>
              </div>
            </div>
            <div class="form-group row">
              <label for="inputPassword3" class="label col-sm-3 form-control-label">Internal Notes</label>
              <div class="col-sm-6">
                <textarea rows="5" nbInput fullWidth shape="round"  placeholder="internal Notes"></textarea>
              </div>
            </div>
          <div class="form-group row">
            <div class="offset-sm-3 col-sm-9">
              <button type="submit" nbButton status="danger">Back</button>
              <button style="margin-left: 10px;" type="submit" nbButton status="primary">Update Class</button>
            </div>
          </div>
        </form>
      </nb-card-body>
    </nb-card>
  </div>
</div>

nodejs应用中的index.js文件

var admin = require("firebase-admin");
const functions = require('firebase-functions');
var fetch = require("node-fetch");


var serviceAccount = require("../xxxxxxxxxxxxxxxxxxxxxxxxxxxx.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://xxxxxxxxxxxxxx.firebaseio.com"
});

const db = admin.firestore();

我还没有在nodejs中编写post数据函数,但我想事先知道如何从angular调用该函数

0 个答案:

没有答案