May Sale! All accounts are 40% off this week.

paboo's avatar
Level 1

oh really?"Property 'form' has no initializer and is not definitely assigned in the constructor. (property) CreateComponent.form: FormGroup"

i know this forum dont support Angular. but i have issue in this. i got this text

Property 'form' has no initializer and is not definitely assigned in the constructor. (property) CreateComponent.form: FormGroup in my web but i cant find solution for this. btw thanks


import { Component, OnInit } from '@angular/core';
import { ProductService } from '../../Services/product.service';
import { Router } from '@angular/router';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
  selector: 'app-create',
  templateUrl: './create.component.html',
  styleUrls: ['./create.component.css']
})
export class CreateComponent implements OnInit {
	form: FormGroup;
  constructor(public ProductService: ProductService) {
   }

  ngOnInit(): void {
  	this.form = new FormGroup({
  		tite: new FormControl('',[Validators.required]),
  		body: new FormControl('',[Validators.required])
  	});
  }
	get f() {
		return this.form.controls;
	}
}

0 likes
3 replies
neilstee's avatar
neilstee
Best Answer
Level 34

@paboo try

	form: FormGroup | undefined;

or

	form!: FormGroup;

Please or to participate in this conversation.