Skip to content

Instantly share code, notes, and snippets.

@Teebo
Created January 31, 2021 12:45
Show Gist options
  • Save Teebo/8d29cf990507d120144affce50526914 to your computer and use it in GitHub Desktop.
Save Teebo/8d29cf990507d120144affce50526914 to your computer and use it in GitHub Desktop.
HobbiesComponent - Uses ControlContainer
import { Component, Input, OnInit } from '@angular/core';
import { ControlContainer, FormGroup } from '@angular/forms';
@Component({
selector: 'app-hobbies',
templateUrl: './hobbies.component.html',
styleUrls: ['./hobbies.component.scss']
})
export class HobbiesComponent implements OnInit {
public hobbiesForm: FormGroup;
@Input() parentForm: FormGroup;
constructor(private controlContainer: ControlContainer) { }
public ngOnInit(): void {
this.hobbiesForm = this.controlContainer.control as FormGroup;
}
public logForms(): void {
console.log('Hobbies form', this.hobbiesForm);
console.log('Parent (Hero) form', this.parentForm);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment