I don't know why the question was down voted, but I feel it may be helpful to other So I am posting the answer.
After multiple attempts to bind child's formgroup I was able to successfully bind value
@Component({
selector: 'my-child',
template: `
<h1>Child</h1>
<div [formGroup]="name">
<input formControlName="firstName">
<input formControlName="lastName">
</div>
`,
providers: [
{provide: NG_VALUE_ACCESSOR, useExisting: Child, multi: true}
]
})
export class Child implements ControlValueAccessor {
name: FormGroup;
constructor(fb: FormBuilder) {
this.name = fb.group({
firstName:[''],
lastName: ['']
});
}
writeValue(value: any) {
if(value) {
this.name.setValue(value);
}
}
registerOnChange(fn: (value: any) => void) {
this.name.valueChanges.subscribe(fn);
}
registerOnTouched() {}
}
http://plnkr.co/edit/ldhPf7LTFVtTFHe9zfAj?p=preview
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…