***Issue: src/app/r-form-example/r-form-example.component.ts:11:3 - error TS2564: Property 'registrationForm' lacks an initializer and is not definitely set in the constructor.
An error has been detected in the code snippet above.
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
@Component({
selector: 'app-r-form-example',
templateUrl: './r-form-example.component.html',
styleUrls: ['./r-form-example.component.css']
})
export class RFormExampleComponent implements OnInit {
registrationForm : FormGroup;
constructor( private fb : FormBuilder) {
}
ngOnInit(): void {
// this.registrationForm = new FormGroup({
// 'firstName': new FormControl(),
// 'lastName': new FormControl(),
// })
this.registrationForm = this.fb.group({
'firstName': new FormControl(),
'lastName':new FormControl()
});
}
addRegistration(){
console.log(this.registrationForm.value);
}
}