【发布时间】:2020-06-08 00:17:22
【问题描述】:
在反应式表单中,错误是无法识别用户名、电子邮件和课程字段。
- 在 ts 文件中我创建了 formGroup
- 在表单控制中,我创建了 3 个属性用户名、电子邮件、课程
-
在 HTML 文件中,我在 formControl 中绑定了同名
<form [formGroup]="myReactiveForm"> <div > <label>User Name</label> <input type="text" [formControl]="username"> </div> <div > <label>Email</label> <input type="text" [formControl]="email"> </div> <div> <select name="course" [formControl]="course"> <option value="Angular">Angular</option> <option value="">Html</option> </select> </div> <button>Submit</button> </form> </div>import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms'; @Component({ selector: 'app-comp', templateUrl: './comp.component.html', styleUrls: ['./comp.component.css'] }) export class CompComponent implements OnInit { myReactiveForm : FormGroup; constructor() { } ngOnInit(): void { this.myReactiveForm = new FormGroup({ 'username' : new FormControl(null), 'email' : new FormControl(null), 'course' : new FormControl(null) }); } }
错误是:
`error TS2339: Property 'username' does not exist on type 'CompComponent'`
8 <input type="text" [formControl]="username">
【问题讨论】:
标签: angularjs typescript