Search code examples
angularform-control

angular 2: get FormGroup by FormControl


can i get the FormGroup - the parent of the FormControl that i have? like this:

    onBlur(formControl: FormControl) {
    var formGroup = formControl.parent // a FormGroup has the FormControl
    if (formControl.dirty) {

        console.log(formControl);
    }

}

Solution

  • I currently have angular 5, but I'm sure on angular 4 it also worked like this:

    formControl.parent

    In my code, for example, I'm getting other control (by name) from the same group with:

    formControl.parent.get(neighbourName)