From 9367e9140212c6606973995a7124b70716985cd6 Mon Sep 17 00:00:00 2001 From: Trotyl Date: Sat, 7 Apr 2018 15:11:02 +0800 Subject: [PATCH] fix(forms): properly handle special properties in FormGroup.get (#22249) closes #17195 PR Close #22249 --- packages/forms/src/model.ts | 2 +- packages/forms/test/form_group_spec.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/forms/src/model.ts b/packages/forms/src/model.ts index ffaa339d99..bbda7f1c6b 100644 --- a/packages/forms/src/model.ts +++ b/packages/forms/src/model.ts @@ -44,7 +44,7 @@ function _find(control: AbstractControl, path: Array| string, del return (>path).reduce((v: AbstractControl, name) => { if (v instanceof FormGroup) { - return v.controls[name] || null; + return v.controls.hasOwnProperty(name as string) ? v.controls[name] : null; } if (v instanceof FormArray) { diff --git a/packages/forms/test/form_group_spec.ts b/packages/forms/test/form_group_spec.ts index 7089f245cf..5b3f622070 100644 --- a/packages/forms/test/form_group_spec.ts +++ b/packages/forms/test/form_group_spec.ts @@ -629,6 +629,18 @@ import {of } from 'rxjs'; }); }); + describe('retrieve', () => { + let group: FormGroup; + + beforeEach(() => { + group = new FormGroup({ + 'required': new FormControl('requiredValue'), + }); + }); + + it('should not get inherited properties', + () => { expect(group.get('constructor')).toBe(null); }); + }); describe('statusChanges', () => { let control: FormControl;