I am trying to add validations to my form using this article.
When I use the constructor with the FormBuilder
it throws errors saying that EXCEPTION: Uncaught (in promise): Error: DI Error
.
test1.component.ts
import { Component, Inject, OnInit } from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';
import { FormComponent } from '../form/form.component';
@Component({
selector: 'app-test1',
templateUrl: './test1.component.html',
styleUrls: ['./test1.component.css']
})
export class Test1Component extends FormComponent {
complexForm : FormGroup;
constructor(@Inject(FormBuilder) fb: FormBuilder){
super();
this.complexForm = fb.group({
'firstName' : "",
'lastName': "",
'gender' : "Female",
'hiking' : false,
'running' : false,
'swimming' : false
});
}
saveForm(){
console.log("Child Form save");
return true;
}
}
How do I fix this ?
I tried to put up a plunker with an example from angular docs but its giving out some other error,
Edit 1:
As suggested by AJT_82, I changed my constructor to constructor(private fb: FormBuilder){
. However its now giving me another error