angular/packages/forms/src
Dylan Hunn 2dbdebc646 feat(forms): Add FormBuilder.nonNullable. (#45852)
With typed forms, all `FormControl`s are nullable by default, because they can be reset to `null`. This behavior is possible to change by passing the option `initialValueIsDefault: true`. However, in a large form, this is extremely cumbersome, as the option must be repeated over and over. Additionally, it is not possible to take full advantage of `FormBuilder`, since `FormBuilder.group` and `FormBuilder.array` will produce nullable controls.

This PR introduces a new accessor `FormBuilder.nonNullable`, which produces *non-nullable* controls. Specifically, any call to `.control` will produce controls with `{initialValueIsDefault: true}`, and calls to `.array` or `.group` that implicitly build inner controls will have the same effect.

```ts
let nfb = new FormBuilder().nonNullable;
let name = nfb.group({who: 'Alex'}); // FormGroup<{who: FormControl<string>}>
name.reset();
console.log(name); // {who: 'Alex'}
```

PR Close #45852
2022-05-04 12:46:05 -07:00
..
directives feat(forms): Implement strict types for the Angular Forms package. (#43834) 2022-04-12 17:37:04 +00:00
model docs(forms): Add documentation for typed forms. (#45841) 2022-05-02 15:03:40 -07:00
directives.ts perf(forms): make RadioControlRegistry class tree-shakable (#41126) 2021-03-16 09:35:14 -07:00
errors.ts refactor(forms): use shared RuntimeError class (#44398) 2022-01-06 23:43:19 +00:00
form_builder.ts feat(forms): Add FormBuilder.nonNullable. (#45852) 2022-05-04 12:46:05 -07:00
form_providers.ts perf(forms): make RadioControlRegistry class tree-shakable (#41126) 2021-03-16 09:35:14 -07:00
forms.ts feat(forms): Add FormBuilder.nonNullable. (#45852) 2022-05-04 12:46:05 -07:00
util.ts refactor(forms): Split up model.ts. (#45217) 2022-03-01 19:49:31 +00:00
validators.ts docs(forms): remove the incorrect set value from previous commit (#45533) 2022-04-07 21:00:25 +00:00
version.ts docs: fix package name in version.ts files in different packages (#41208) 2021-05-10 10:26:34 -04:00