角 8 上有一個(gè)表格我的form.component.html<div class="container"><form novalidate [formGroup]="registrationForm"> <div class="form-group"> <label for="firstName">Имя:</label> <input #spy required pattern=[A-Za-zА-Яа-яЁё]{2,} name="firstName" id="firstName" type="text" class="form-control" formControlName="firstName"> </div> <div class="form-group"> <label for="lastName">Фамилия:</label> <input #spy required pattern=[A-Za-zА-Яа-яЁё]{2,} name="lastName" id="lastName" type="text" class="form-control" formControlName="lastName"> </div> <div class="form-group"> <label for="email">E-mail:</label> <input #spy required email name="email" id="email" type="email" class="form-control" formControlName="email"> </div> <!--{{ spy.className }}--> <button type="submit" class="btn btn-succes" (click)="submit(myForm)">Отправить</button></form>當(dāng)用戶寫入數(shù)據(jù)時(shí),提交按鈕應(yīng)使用 POST 方法向 API 發(fā)送數(shù)據(jù)。如果您需要任何代碼,請(qǐng)發(fā)表評(píng)論ts 代碼:import { FormGroup, FormControl } from '@angular/forms';import {HttpClient} from '@angular/common/http';@Component({ selector: 'app-my-form', templateUrl: './my-form.component.html', styleUrls: ['./my-form.component.css']})export class MyFormComponent implements OnInit { registrationForm: FormGroup; constructor() { } ngOnInit() { this.registrationForm = new FormGroup({ firstName: new FormControl(), lastName: new FormControl(), email: new FormControl() }); }}```
在api上提交表單的post方法
千萬里不及你
2021-10-21 16:42:07