Angular 6-发布到Google表格未定义

时间:2018-10-28 09:26:00

标签: angular google-sheets

在向Google表格发送POST消息时,我在电子表格上始终收到未定义的条目。该邮件已从我的客户端成功发布,但似乎未由Google Sheets API端点处理。

我该如何解决?我正在按照教程here进行操作。

表格代码

.innerGrid h1 {
    margin: 0;
}

Google表格

enter image description here

Google表格代码

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { Breakpoints, BreakpointState, BreakpointObserver } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';

@Component({
  templateUrl: './about.component.html'
})
export class AboutComponent implements OnInit {
  isMobile: Observable<BreakpointState>;
  submitted = false;
  registerFormGroup: FormGroup;

  constructor(
    private breakpointObserver: BreakpointObserver,
    private formBuilder: FormBuilder) { }

  private scriptURL = 'https://script.google.com/macros/s/123/exec';
  registerForm = document.forms['registerForm'];

  ngOnInit() {
    this.isMobile = this.breakpointObserver.observe([ Breakpoints.Handset, Breakpoints.Tablet ]);

    this.registerFormGroup = new FormGroup({
      name: new FormControl(),
      email: new FormControl()
    });

    this.registerForm = this.formBuilder.group({
      name: ['', Validators.required],
      email: ['', [Validators.required, Validators.email]]
    });
  }

  get f() { return this.registerForm.controls; }

  onSubmit() {
    this.submitted = true;

    // Stop here if form is invalid

    if (this.registerForm.invalid) {
        return;
    }

    const formObject = this.registerForm.getRawValue();
    const serializedForm = JSON.stringify(formObject);

    if (environment.production === false) {
      console.log(serializedForm);
    }

    fetch(this.scriptURL, { method: 'POST', body: serializedForm})
      .then(response => console.log('Success!', response))
      .catch(error => console.error('Error!', error.message));
  }
}

0 个答案:

没有答案