Commit graph

244 commits

Author SHA1 Message Date
Kristiyan Kostadinov
c2d376b85a feat(core): make SimpleChanges generic (#64535)
Currently it's easy to make a mistake when accessing properties on `SimpleChanges`, because the keys aren't typed. These changes add an optional generic to the interface so that users can get a compilation error if they make a typo.

A few things to note:
1. The generic argument is optional and we revert to the old behavior if one isn't passed for backwards compatibility.
2. All of the keys are optional, because they aren't guaranteed to be present for any `ngOnChanges` invocation.
3. We unwrap the values of input signals to match the behavior at runtime.

Fixes #17560.

PR Close #64535
2025-10-20 17:49:39 +00:00
Joey Perrott
13e18cafff build: migrate vscode extension into repo (#63924) (#64049)
Migrate the vscode extension for angular into this repository.

PR Close #63924

PR Close #64049
2025-10-15 10:37:02 -07:00
Matthieu Riegler
c0d88c37c9 fix(forms): Emit FormResetEvent when resetting control (#64024)
Prior to this change, the event was emitted by the Form Directive. With the change, it is now emitted at the control level.

fixes #58894

PR Close #64024
2025-09-24 16:48:32 +00:00
Kristiyan Kostadinov
f5b50ec20d refactor: clean up explicit standalone flags from tests (#63963)
Since standalone is the default, we can dropn the `standalone: true` flags from our tests.

PR Close #63963
2025-09-22 14:27:34 +00:00
Andrew Scott
c3576506b3 refactor(core): Update tests for zoneless by default (#63668)
This updates tests and examples only to prepare for zoneless by default.

These changes were identified and made as part of #63382. Anything that
failed gets `provideZoneChangeDetection` unless the fixes were easily
and quickly determined.

It also adds the zoneless provider to the `initTestEnvironment` calls
for tests in this repo to prevent regressions before #63382 is merged.

PR Close #63668
2025-09-09 14:41:56 -07:00
Joey Perrott
2fcafb65c5 build: rename defaults2.bzl to defaults.bzl (#63383)
Use defaults.bzl for the common macros

PR Close #63383
2025-08-25 15:45:01 -07:00
Matthieu Riegler
0dd95c503f feat(forms): Add FormArrayDirective (#55880)
The `FormArrayDirective` will allow to have a `FormArray` as a top-level form object.

* `NgControlStatusGroup` directive will be applied to the `FormArrayDirective`
* `NgForm` will still create a `FormGroup`

Fixes angular#30264

BREAKING CHANGE: This new directive will conflict with existing FormArray directives or formArray inputs on the same element.

PR Close #55880
2025-08-21 09:38:37 -07:00
Bjorn 'Bjeaurn
c353497a01 feat(forms): add support for pushing an array of controls to formarray (#57102)
Enables users to add an array of FormControls to a FormArray using its existing .push() method,
instead of pushing each new FormControl one by one triggering events along the way.

PR Close #57102
2025-08-06 11:20:18 +02:00
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +00:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
Joey Perrott
36d5048429 build: migrate final non-zone.js jasmine tests (#62169)
Migrate the final remaining non-zone.js package jasmine tests to the new toolchain

PR Close #62169
2025-06-24 08:46:39 +00:00
Theodore Brown
4f0221e193 fix(forms): improve select performance (#61949)
We defer the update until after rendering
is complete for two reasons: first, to avoid repeatedly calling
`writeValue` on every option element until we find the selected one
(could be the very last element). Second, to ensure that we perform the
write after the DOM elements have been created (this doesn't happen
until the end of change detection when animations are enabled).

This is needed to efficiently set the select value when adding/removing options. The
previous approach resulted in exponentially more `_compareValue` calls than the number
of option elements (issue angular#41330).

Finally, this PR fixes an issue with delayed element removal when using the animations
module (in all browsers). Previously when a selected option was removed (so no option
matched the ngModel anymore), Angular changed the select element value before actually
removing the option from the DOM. Then when the option was finally removed from the DOM,
the browser would change the select value to that of the first option, even though it
didn't match the ngModel (issue angular#18430). Note that this is still
somewhat of an application problem when using `ngModel`. The model value
still needs to be updated to a valid value when the selected value is
deleted or it will be out of sync with the DOM.

Fixes #41330, fixes #18430.

PR Close #61949
2025-06-10 13:13:13 -07:00
Bouguima, Walid
610bebfce9 fix(forms): Allow ControlState as reset arguments for FormGroup/FormRecord (#55860)
This change also decorelate the `reset` type argument from `TValue` by adding a 3rd generic parameter to `AbstractControl`.
This improves the typings overall.

PR Close #55860
2025-05-21 17:26:23 +00:00
Joey Perrott
e11f48f65e build: migrate forms to rules_js (#61535)
Migrate forms to use ng_project and ts_project

PR Close #61535
2025-05-21 09:16:05 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
Andrew Scott
953c4b2580 feat(core): Move zoneless change detection to dev preview (#60748)
This commit moves zoneless from experimental to developer preview.

* Update tag on provider API
* Remove "experimental" from provider name
* Move documentation from "experimental features" to "Best practives ->
  Performance" (at least temporarily until there is a better place)

BREAKING CHANGE: `provideExperimentalZonelessChangeDetection` is
renamed to `provideZonelessChangeDetection` as it is now "Developer
Preview" rather than "Experimental".

PR Close #60748
2025-04-23 11:47:56 +02:00
Gabriel Bergoc
be995623cd fix(forms): make NgForm emit FormSubmittedEvent and FormResetEvent (#60887)
Currently, only forms created with `FormGroupDirective` emit events on
form submission and resetting. This commit extends this behavior to
Template-driven forms also.

Related to #58894

PR Close #60887
2025-04-22 13:04:40 +02:00
Domenico Gemoli
a07ee60989 feat(forms): add markAllAsDirty to AbstractControl (#58663)
Adds the `markAllAsDirty` method to the `AbstractControl` class. This method will mark the control and all its
descendants as dirty.

I pretty much just duplicated the behaviour and tests of `markAllAsTouched`.

Fixes #55990

PR Close #58663
2025-04-02 18:25:32 +00:00
Matthieu Riegler
bdfbd54932 feat(forms): Allow to reset a form without emitting events (#60354)
This change  add an option paramter to `resetForm` that is passed to the FormGroup.

fixes #60274

PR Close #60354
2025-04-02 11:36:24 +00:00
Andrew Kushnir
be7c8d4fc6 refactor(forms): convert scripts within packages/forms to relative imports (#60624)
This commit updates scripts within `packages/forms` to relative imports as a prep work to the upcoming infra updates.

PR Close #60624
2025-03-31 19:22:09 +00:00
Matthieu Riegler
81fe0536fd fix(forms): Make sure statusChanges is emitted (#57098)
In the cases multiple updates with `emitEvent:false` were requests, `shouldHaveEmitted` wasn't passed correctly and and requests updates were trashed.
This commit fixes this.

Fixes #56999

PR Close #57098
2025-03-06 09:21:00 -08:00
Matthieu Riegler
cf36951f83 fix(forms): Fix typing on FormRecord. (#59993)
Priori to this change, `ɵRawValue` of a `FormRecord` returned a `Partial`. This commit fixes it.

fixes #59985

PR Close #59993
2025-02-18 19:28:36 +00:00
Jeremias Peier
fa0c3e3210 feat(forms): support type set in form validators (#45793)
Previously, using `Validators.required`, `Validators.minLength` and `Validators.maxLength` validators don't work with sets because a set has the `size` property instead of the `length` property. This change enables the validators to be working with sets.

PR Close #45793
2025-02-05 08:59:55 -08:00
Alan Agius
7de7c52769 build: remove usages of useDefineForClassFields: false (#58297)
When setting `"useDefineForClassFields": false`, static fields are compiled within a block that relies on the `this` context. This output makes it more difficult for bundlers to treeshake and eliminate unused code.

PR Close #58297
2024-10-28 12:26:05 -07:00
Andrew Kushnir
79d9be3e63 Revert "feat(forms): add ability to clear a FormRecord (#50750)" (#58315)
This reverts commit 3e7d724037.

PR Close #58315
2024-10-22 14:04:45 -07:00
Andrew Kushnir
a5b0394313 Revert "test(forms): add unit test (#50750)" (#58315)
This reverts commit b0c4c1fd2b.

PR Close #58315
2024-10-22 14:04:45 -07:00
Emmanuel Roux
b0c4c1fd2b test(forms): add unit test (#50750)
Add unit test for statusChange events

PR Close #50750
2024-10-22 07:36:22 -07:00
Emmanuel Roux
3e7d724037 feat(forms): add ability to clear a FormRecord (#50750)
Add new `clear()` method to `FormRecord`

PR Close #50750
2024-10-22 07:36:22 -07:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Andrew Scott
00bde8b1c2 fix(forms): Make NgControlStatus host bindings OnPush compatible (#55720)
This commit makes the host bindings of `NgControlStatus[Group]`
compatible with `OnPush` components. Note that this intentionally _does not_
expose any new APIs in the forms module. The goal is only to remove
unpreventable `ExpressionChangedAfterItHasBeenCheckedError` in the forms
code that developers do not have control over.

PR Close #55720
2024-06-18 11:35:34 -07:00
Matthieu Riegler
b2445a0953 fix(core): link errors to ADEV (#55554) (#56038)
Console error links will now point to adev.

PR Close #55554

PR Close #56038
2024-05-28 12:50:53 +02:00
Pawel Kozlowski
760207b254 Revert "fix(core): link errors to ADEV (#55554)" (#56031)
This reverts commit dd0700ff1d.
We will need G3 patch cleanup before this one can land.

PR Close #56031
2024-05-23 13:57:53 +02:00
Matthieu Riegler
dd0700ff1d fix(core): link errors to ADEV (#55554)
Console error links will now point to adev.

PR Close #55554
2024-05-23 11:58:54 +02:00
Matthieu Riegler
53b0d6adb8 fix(forms): Allow canceled async validators to emit. (#55134)
With this change, If an async validator that should have emitted was cancelled by a non-emitting validator, the status change will be reported on the `AbstractControl.events` observable.

This issue can happen when a `FormControl` is added to a `FormGroup` and a FormGroupDirective/FormControlDirective trigger a non-emitting validation (which cancels the initial validator execution).

Note: The behavior remains the same of the existing `statusChanges` observable as the change was too breaking to land in G3.

fixes: angular#41519

PR Close #55134
2024-05-15 08:56:25 -07:00
Matthieu Riegler
fedeaac8ba fix(forms): Add event for forms submitted & reset (#55667)
This commit adds 2 new events to the unified control event observable.

PR Close #55667
2024-05-09 09:21:14 -07:00
fdonzello
c001b05c77 refactor(forms): added control name in console errors (#55397)
When a formControlName is used without a parent formGroup, an error is
logged in the console. Before this commit, there was no information
about which control had the issue. Now, it's reported and the
troubleshoot is much faster.

PR Close #55397
2024-04-23 15:16:57 -07:00
Joey Perrott
a2aca69bd3 refactor: migrate forms to prettier formatting (#55423)
Migrate formatting to prettier for forms from clang-format

PR Close #55423
2024-04-19 13:49:24 -07:00
Matthieu Riegler
3547e1e769 refactor(forms): emit status/value event in a consistant order (#55198)
We emit `ValueChangeEvent` first and then `StatusChangeEvent`

PR Close #55198
2024-04-09 15:21:39 -07:00
cexbrayat
9c776d6802 docs(forms): add docs for emitEvent flag (#55249)
PR Close #55249
2024-04-09 10:31:10 -07:00
Matthieu Riegler
1c736dc3b2 feat(forms): Unified Control State Change Events (#54579)
This commit introduces a new method to subscribe to on every `AbstractControl` subclass.
It allows to track value, pristine, touched and status changes on a given control.

Fixes #10887

PR Close #54579
2024-04-03 17:12:04 +00:00
Andrew Scott
658cf8c384 fix(core): ComponentFixture stability should match ApplicationRef (#54949)
This change aligns the stability of `ComponentFixture` with that of
`ApplicationRef`, preventing confusing differences between the two as
more APIs start using the `PendingTasks` that may not be tracked by
`NgZone`.

BREAKING CHANGE: `ComponentFixture.whenStable` now matches the
`ApplicationRef.isStable` observable. Prior to this change, stability
of the fixture did not include everything that was considered in
`ApplicationRef`. `whenStable` of the fixture will now include unfinished
router navigations and unfinished `HttpClient` requests. This will cause
tests that `await` the `whenStable` promise to time out when there are
incomplete requests. To fix this, remove the `whenStable`,
instead wait for another condition, or ensure `HttpTestingController`
mocks responses for all requests. Try adding `HttpTestingController.verify()`
before your `await fixture.whenStable` to identify the open requests.
Also, make sure your tests wait for the stability promise. We found many
examples of tests that did not, meaning the expectations did not execute
within the test body.

In addition, `ComponentFixture.isStable` would synchronously switch to
true in some scenarios but will now always be asynchronous.

PR Close #54949
2024-03-27 11:01:28 -07:00
Andrea Canciani
f3b624553a refactor: fix a number of typos throughout the codebase (#55018)
Fix some typos detected using spellchecking tools, both in
documentation and in code (comments, identifiers).

PR Close #55018
2024-03-27 10:54:31 -07:00
Kristiyan Kostadinov
c07805612f test(core): clean up unnecessary nesting in old tests (#52239)
A lot of our tests are wrapped in `{}` which serves no purpose, aside from increasing the nesting level and, in some cases, causing confusion. The braces appear to be a leftover from a time when all tests were wrapped in a `function main() {}`. The function declaration was removed in #21053, but the braces remained, presumably because it was easier to search&replace for `function main()`, but not to remove the braces at the same time.

PR Close #52239
2023-10-19 09:26:15 -07:00
Matthieu Riegler
43115da986 refactor(forms): Log a warning when FormGroup keys include a dot. (#50642)
Due to the dotted synthax to resolve controls, keys in FormGroups cannot include dots.

fixes #50608

PR Close #50642
2023-10-18 12:11:25 -07:00
Matthieu Riegler
ddd7212ee2 fix(forms): reset() call with null values on nested group (#48830)
Non typed forms allow to pass null to nested groups when calling `formGroup.reset()`, this commit prevent an undefined access.

fixes #20509

PR Close #48830
2023-10-10 15:34:31 -07:00
Matthieu Riegler
e9b9fd4579 refactor(forms): Use the Writable type when overwriting readonly properties. (#49754)
The `Writable` type is usefull when we want overwrite readonly properties and we still want to maintain code navigation/reference. It should be use instead of `any` type assertions for example.

PR Close #49754
2023-09-22 10:02:13 -07:00
Kristiyan Kostadinov
52cc7f839b build: align with internal tsconfig options (#51728)
Currently internally Angular has some customized tsconfig files, because we don't align with the tsconfig of the rest of g3. These changes enable `noImplicitReturns` and `noPropertyAccessFromIndexSignature` to align better with the internal config.

PR Close #51728
2023-09-12 11:39:42 -07:00
Matthieu Riegler
a871e23857 docs: remove duplicate words. (#51215)
Using the `\b(\w+)\s+\1\b` we can find duplicate word. Let's remove them.

PR Close #51215
2023-08-01 12:08:33 -07:00