【发布时间】:2021-07-29 10:29:53
【问题描述】:
错误:src/app/form-page/form-page.component.html:1:29 - 错误 TS2554:预期 1 个参数,但得到 0。
src/app/form-page/form-page.component.ts:8:16
templateUrl: './form-page.component.html', ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 组件FormPageComponent的模板出错。
这是我的html代码
```
<mat-form-field (ngSubmit)="onSubmit()" class="form-register">
<p>
<mat-form-field appearance="outline">
<mat-label>First Name</mat-label>
<input matInput
type="text"
placeholder="First Name"
ngModel
required>
</mat-form-field>
</p>
<p>
<mat-form-field appearance="outline">
<mat-label>Last Name</mat-label>
<input matInput
placeholder="Last Name"
ngModel
required>
</mat-form-field>
</p>
<p>
<mat-form-field appearance="outline">
<mat-label>Age</mat-label>
<input matInput
placeholder="Age"
ngModel
required>
</mat-form-field>
</p>
<p>
<mat-form-field appearance="outline">
<mat-label>Gender</mat-label>
<mat-select ngModel required>
<mat-option>Male</mat-option>
<mat-option>Female</mat-option>
<mat-option>Transgender</mat-option>
<mat-option>Prefer Not To Say</mat-option>
</mat-select>
</mat-form-field>
</p>
<p>
<mat-form-field appearance="outline">
<mat-label>Mobile Number</mat-label>
<input matInput
placeholder="Mobile Number"
ngModel
required>
</mat-form-field>
</p>
<button mat-button (click)="creationDone()"> Submit</button>
</mat-form-field>
这是我的 ts 代码
import { Component, OnInit, ViewChild,Inject } from '@angular/core';
import { FormControl, FormGroup, NgForm, NgModel } from '@angular/forms';
import {MatDialog, MatDialogRef,MAT_DIALOG_DATA} from '@angular/material/dialog';
@Component({
selector: 'app-form-page',
templateUrl: './form-page.component.html',
styleUrls: ['./form-page.component.scss']
})
export class FormPageComponent {
@ViewChild('f') userform:NgForm;
onSubmit(form){
console.log(form.value);
}
constructor(public dialog: MatDialog) {}
creationDone() {
this.dialog.open(SubmitDialog);
}
}
【问题讨论】:
标签: html angular typescript forms angular-material