Skip to content

Instantly share code, notes, and snippets.

@dancornilov
Created March 26, 2019 10:20
Show Gist options
  • Save dancornilov/7b58f51d72b43d8d70f9ad9a80d52153 to your computer and use it in GitHub Desktop.
Save dancornilov/7b58f51d72b43d8d70f9ad9a80d52153 to your computer and use it in GitHub Desktop.
Get FormControl name
/**
* Extract control name from formGroup
*
* @return string
*/
public getControlName(): string {
let controlName = null;
const parent = this.control['parent'];
if (parent instanceof FormGroup) {
for (const name in parent.controls) {
if (this.control === parent.controls[name]) {
controlName = name;
}
}
}
return controlName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment