要求:
我需要使用action
中的联系表单的Angular
属性发布表单数据。
问题:
如果我们使用此表单创建静态文件,则该解决方案有效。但是在action
模板中使用属性angular
似乎不起作用。单击时似乎没有执行任何操作。
我的表单:
<form
id="gform"
action="https://script.google.com/sampleUrl"
method="POST"
[formGroup]="form"
fxLayout="column"
fxLayoutAlign="space-evenly stretch">
<mat-form-field>
<input type="text" matInput placeholder="Name" formControlName="name" name="Name" required>
<mat-error *ngIf="form.get('name').invalid">Please enter a Name</mat-error>
</mat-form-field>
<mat-form-field>
<input matInput placeholder="e-mail" formControlName="email" name="Email" required>
<mat-error *ngIf="form.get('email').invalid">Please enter a valid e-mail</mat-error>
</mat-form-field>
<mat-form-field>
<input matInput placeholder="Number" formControlName="number" name="Phone" required>
<mat-error *ngIf="form.get('number').invalid">Please enter phone number</mat-error>
</mat-form-field>
<button type="submit" mat-raised-button color="primary" >Submit</button> -->
</form>
版本信息:
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 6.2.2
Node: 10.5.0
OS: win32 x64
Angular: 6.1.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.8.2
@angular/cdk 6.4.7
@angular/cli 6.2.2
@angular/flex-layout 6.0.0-beta.18
@angular/material 6.4.7
@ngtools/webpack 6.0.8
@schematics/angular 0.8.2
@schematics/update 0.8.2
rxjs 6.3.2
typescript 2.9.2
webpack 4.8.3
注意::我正在尝试使用Google电子表格api写入Google文档。使用方法调用
时遇到的CORS问题答案 0 :(得分:0)
通常,如果您想获取数据,请使用(提交)
<form [formGroup]="form" (submit)="submit(form)">...</form>
如果您的.ts
submit(form)
{
if (form.valid)
this.httpClient.post("https://script.google.com/sampleUrl",form.value)
.subscribe(res=>console.log(res))
}
如果要重定向到新页面,请使用简单的表单,但不要忘记写 ngNoForm ,https://angular.io/api/forms/NgForm,否则Angular会将您的表单转换为angular形式