Skip to content

Commit c1057c6

Browse files
SkyZeroZxthePunderWoman
authored andcommitted
docs: add formArray clear() example clarifies array manipulation
1 parent cc07534 commit c1057c6

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

adev/src/content/guide/forms/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ The `[formControl]` directive links the explicitly created `FormControl` instanc
7373
The following component implements an input field for a single control, using reactive forms.
7474
In this example, the form model is the `FormControl` instance.
7575

76-
<docs-code path="adev/src/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.ts"/>
76+
<docs-code language="angular-ts" path="adev/src/content/examples/forms-overview/src/app/reactive/favorite-color/favorite-color.component.ts"/>
7777

7878
IMPORTANT: In reactive forms, the form model is the source of truth; it provides the value and status of the form element at any given point in time, through the `[formControl]` directive on the `<input>` element.
7979

@@ -84,7 +84,7 @@ The directive `NgModel` creates and manages a `FormControl` instance for a given
8484

8585
The following component implements the same input field for a single control, using template-driven forms.
8686

87-
<docs-code path="adev/src/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.ts"/>
87+
<docs-code language="angular-ts" path="adev/src/content/examples/forms-overview/src/app/template/favorite-color/favorite-color.component.ts"/>
8888

8989
IMPORTANT: In a template-driven form the source of truth is the template. The `NgModel` directive automatically manages the `FormControl` instance for you.
9090

adev/src/content/guide/forms/typed-forms.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ This `FormArray` will have the inner controls type `FormControl<string|null>`.
110110

111111
If you want to have multiple different element types inside the array, you must use `UntypedFormArray`, because TypeScript cannot infer which element type will occur at which position.
112112

113+
A `FormArray` also provides a `clear()` method to remove all controls it contains:
114+
115+
```ts
116+
const aliases = new FormArray([new FormControl('ngDev'), new FormControl('ngAwesome')]);
117+
aliases.clear();
118+
console.log(aliases.length); // 0
119+
```
120+
113121
## `FormGroup` and `FormRecord`
114122

115123
Angular provides the `FormGroup` type for forms with an enumerated set of keys, and a type called `FormRecord`, for open-ended or dynamic groups.

0 commit comments

Comments
 (0)