Skip to content

Commit dc95814

Browse files
arturovtkirjs
authored andcommitted
docs: add documentation for NG1002
Adds a documentation page for the NG01002 runtime error thrown by FormGroup and FormArray when setValue is called with a value that is missing an entry for one or more registered controls. The error code is also changed from positive (1002) to negative (-1002) so that Angular appends a link to the error reference page in dev mode, consistent with how other documented errors (e.g. NG01101, NG01203) are handled. (cherry picked from commit 0304228)
1 parent 05d9b97 commit dc95814

4 files changed

Lines changed: 49 additions & 2 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Missing Control Value
2+
3+
This error occurs when you call `setValue` on a `FormGroup` or `FormArray` but the value you pass is missing an entry for one of the registered controls.
4+
5+
`setValue` is strict — it expects a value for every control. If you want to update only some controls, use `patchValue` instead.
6+
7+
## Debugging the error
8+
9+
Check which control is named in the error message, then make sure your value object includes it.
10+
11+
A common source of this error is spreading an object that doesn't have all the keys:
12+
13+
```typescript
14+
const someValue = {first: 'Nancy'}; // 'last' is missing
15+
16+
form.setValue({...someValue}); // throws NG01002
17+
```
18+
19+
This can happen if `someValue` comes from an API response, a partial state update, or a type that doesn't fully match the form structure. In those cases, either fill in the missing keys explicitly or switch to `patchValue`.
20+
21+
### FormGroup
22+
23+
```typescript
24+
const form = new FormGroup({
25+
first: new FormControl(''),
26+
last: new FormControl(''),
27+
});
28+
29+
// 'last' is not in the value — throws NG01002
30+
form.setValue({first: 'Nancy'});
31+
32+
// both controls are covered — works fine
33+
form.setValue({first: 'Nancy', last: 'Drew'});
34+
```
35+
36+
### FormArray
37+
38+
```typescript
39+
const formArray = new FormArray([new FormControl(''), new FormControl('')]);
40+
41+
// only one value for two controls — throws NG01002
42+
formArray.setValue(['Nancy']);
43+
44+
// one value per control — works fine
45+
formArray.setValue(['Nancy', 'Drew']);
46+
```

adev/src/content/reference/errors/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
| `NG0951` | [Child query result is required but no value is available](errors/NG0951) |
3737
| `NG0955` | [Track expression resulted in duplicated keys for a given collection](errors/NG0955) |
3838
| `NG0956` | [Tracking expression caused re-creation of the DOM structure](errors/NG0956) |
39+
| `NG01002` | [Missing Control Value](errors/NG01002) |
3940
| `NG01101` | [Wrong Async Validator Return Type](errors/NG01101) |
4041
| `NG01203` | [Missing value accessor](errors/NG01203) |
4142
| `NG02200` | [Missing Iterable Differ](errors/NG02200) |

goldens/public-api/forms/errors.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const enum RuntimeErrorCode {
2121
// (undocumented)
2222
MISSING_CONTROL = 1001,
2323
// (undocumented)
24-
MISSING_CONTROL_VALUE = 1002,
24+
MISSING_CONTROL_VALUE = -1002,
2525
// (undocumented)
2626
NAME_AND_FORM_CONTROL_NAME_MUST_MATCH = 1202,
2727
// (undocumented)

packages/forms/src/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const enum RuntimeErrorCode {
1414
// Structure validation errors (10xx)
1515
NO_CONTROLS = 1000,
1616
MISSING_CONTROL = 1001,
17-
MISSING_CONTROL_VALUE = 1002,
17+
MISSING_CONTROL_VALUE = -1002,
1818

1919
// Reactive Forms errors (1050-1099)
2020
FORM_CONTROL_NAME_MISSING_PARENT = 1050,

0 commit comments

Comments
 (0)