As you can see I have a father form component with a component child.
The {{myFormFather.value}} show me nickName
value and name
value but dont show age
value.
{{myFormFather.status}} it dont recognice the component child. Is like my child was a phantom, why?
my-form-father.html
<form [formGroup]="myFormFather" (ngSubmit)="onSubmit()">
<input formControlName="nickName">
<input formControlName="name">
<my-form-child
[age]="myFormFather">
</my-form-child>
<button type="submit"
[disabled]="myFormFather.invalid">Save
</button>
</form>
my-form-father.ts
myFormFather = new FormGroup({
nickName: new FormControl(),
name: new FormControl()
});
constructor(private fb:FormBuilder) {}
ngOnInit() {this.createForm()}
createForm() {
this.myFormFather = this.fb.group({
nickName: ['', [Validators.required],
name: ['', [Validators.required]
});
}
my-form-child.html
<div [formGroup]="ageForm">
<input formControlName="age">
</div>
my-form-child.ts
@Input() ageForm = new FormGroup({
age: new FormControl()
});
constructor(private fb:FormBuilder) {}
ngOnInit() {this.createForm()}
createForm() {
this.ageForm = this.fb.group({
age: ['', [Validators.required]]
});
}
[age]="myFormFather"
input in your child component? And what are you expecting if you create new FormGroup even twice in child component? – yurzui Mar 2 '18 at 6:01