Skip to content

Instantly share code, notes, and snippets.

@goughjo02
Last active February 25, 2019 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goughjo02/b8e43b61f0b2b27c242fbdf132b2027a to your computer and use it in GitHub Desktop.
Save goughjo02/b8e43b61f0b2b27c242fbdf132b2027a to your computer and use it in GitHub Desktop.
// app-parent.ts
@Component({
selector: 'example-parent',
template: `./example-parent.html`,
styleUrls: ['./parent.component.css']
})
export class ParentComponent implements OnInit {
formBroadcast: Subject<FormGroup> = new BehaviorSubject(null);
form: FormGroup;
constructor(
private formBuilder: FormBuilder
) { }
ngOnInit() {
this.createForm();
this.subscribeForm();
}
subscribeForm(): void {
this.formBroadcast.subscribe(e => {
const { name, age } = e;
this.form.get('name').setValue(name);
this.form.get('age').setValue(age);
})
}
createForm(): void {
this.form = this.formBuilder.group({
name: new FormControl(''),
age: new FormControl(-1)
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment