属性 .... 没有初始化器,也没有在构造函数中明确分配

时间:2021-06-02 23:53:59

标签: angular angular-reactive-forms

我正在学习 Angular 反应式表单,但遇到了一个错误。

按照本教程 https://www.youtube.com/watch?v=JeeUY6WaXiA 我到达他添加 myForm: FormGroup; 的部分,但出现以下错误:

Property 'myForm' has no initializer and is not definitely assigned in the constructor.

这是我的src/app/components/form/form.component.ts

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';

@Component({
  selector: 'app-form',
  templateUrl: './form.component.html',
  styleUrls: ['./form.component.css']
})
export class FormComponent implements OnInit {

  myForm: FormGroup;  

  constructor(private fb: FormBuilder) { }

  ngOnInit(): void {
    this.myForm = this.fb.group({
      website: '',
      password: ''
    })
  }

}

0 个答案:

没有答案