Last active
February 25, 2019 16:40
-
-
Save goughjo02/b8e43b61f0b2b27c242fbdf132b2027a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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