angular / angular/angular

There is no FormControl instance attached to form control element with name: xxx

Open
#14,057 41 comments 47 reactions 0 assignees View on GitHub
area: forms freq2: medium P3 state: confirmed type: bug/fix
Dominant language
TypeScript
Stars
101k
Forks
27.5k
Avg merge
1d 19h
Merged PRs (30d)
288

Description

**I'm submitting a ...** (check one with "x")
```
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
```

**Current behavior**

When using ReactiveForms and we override old form group with the new one (using for example `this.form = new FormGroup(...)`) an error occurs (the error is mentioned in the title).
(The error can be seen in console).

**Expected behavior**

No error happens.

**Minimal reproduction of the problem with instructions**

http://plnkr.co/jVMbtQGKeYhPsCkrzQN8
The error can be seen after 3 seconds (I used set timeout in the example). Error should be visible in console.

**What is the motivation / use case for changing the behavior?**

I understand that this is not the best way to use form groups, i should check if they are already created, and create it only if necessary. However, this bug indicates (I concluded this from stacktrace) that control set-up doesn't work after it's been cleaned up. This should not be the case. Problem occurs because Angular's cleanUpControl function sets up change callback to its own handler (the handler just throws error), and then in setUpControl function, Angular calls write value BEFORE it registers callback handler. It means that the last handler remembered by the custom control was cleanUpControl's handler which only throws an error. Functions setUpControl and cleanUpControl can be found in `@angular/forms/src/directives/shared.js`

**Please tell us about your environment:**

Project is set-up using angular-cli, but it doesn't really affect the problem if I change the setup.

* **Angular version:** 2.0.X

2.4.4

* **Browser:** [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]

I tested this on Chrome and Firefox, they both reproduce the problem

* **Language:** [all | TypeScript X.X | ES6/7 | ES5]

Typescript

* **Node (for AoT issues):** `node --version` =

Contributor guide

Open the contributing guide

Research direction

Start with @angular/forms/src/directives/shared.js, focusing on setUpControl and cleanUpControl, then run the linked Plunker reproduction and observe the console after three seconds. Done means replacing the FormGroup no longer produces the “There is no FormControl instance attached” error in the reported browser scenarios.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.