【发布时间】:2023-01-31 06:46:57
【问题描述】:
我正在尝试关注tutorial(Angular 15),但它不起作用 https://gist.github.com/jhades/2d678f0140a013ec3d0b5eb2e450944c#file-01-ts
@Component({
selector: 'login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent {
form = this.fb.group({
email: ["", {
validators: [Validators.required, Validators.email]
}],
password: ['', [Validators.required, Validators.minLength(8)]]
});
constructor(private fb: FormBuilder) {
}
login() {
}
}
投掷
TypeError: Cannot read properties of undefined (reading 'group')
FormBuilder 似乎没有实例化。我已经尝试以“通常”的方式来做到这一点 https://gist.github.com/jhades/2d678f0140a013ec3d0b5eb2e450944c#file-02-ts 有效(尽管我必须这样做 form!: FormGroup),但它明确声明不要使用这种方式,因为那样你就失去了形式输入。
【问题讨论】:
标签: angular angular-reactive-forms formbuilder