269 Commits
Author SHA1 Message Date
Shuaib Hasan Akib f499ad0c7c refactor: remove redundant standalone: true from tests
Standalone is the default, so the explicit flag is redundant. Remove the
occurrences added to core, platform-browser, forms and router tests since
the last cleanup.
2026-11-11 12:38:00 -08:00
Максим Иванов 0a61a687c4 perf(forms): match multi-select identities in a single pass
Avoid repeated option scans when a multi-select receives multiple values
with the default identity comparison. Match registered options against a
Set of requested values and retain the first match for duplicate options.

Keep signed zero distinct, ignore sparse-array holes, and preserve custom
comparator invocation order. Apply all selection writes synchronously and
cover option setters, removal, duplicate identities, and model updates.
2026-10-24 13:54:13 -07:00
arturovt 63f4bd4c7e fix(forms): don't crash when formControlName has no matching control
Even tho reactive forms might be considered legacy now, this fix covers
a real production case.

Prior to this commit, a `formControlName` with no control for it in the
form group crashed in production with a raw `TypeError: Cannot read
properties of null (reading '_rawValidators')`. The error said nothing
about forms or which control was missing, so it was hard to trace back
to the template. A common way to hit it: the template and the form group
are built from the same list but with two different filters, so an item
passes the template's filter but was never given a control.

`AbstractFormDirective.addControl` read `this.form.get(dir.path)` and
passed the result into `_setupWithForm` without a null check. In dev
mode this was still caught earlier, in `setUpControlValueAccessor`
("Cannot find control with path"). In production `ngDevMode` strips that
check away, so the null control reached `setUpValidators`, which
dereferences it right away and threw the bare `TypeError`.

With this fix, `addControl` checks the control first and throws a coded
`RuntimeError` (NG01055), with a docs page on angular.dev. The check is
not gated behind `ngDevMode`, since the crash it prevents is a production
one. The message stays `ngDevMode`-only and lists the sibling controls
that exist at that path, which is usually enough to spot a name mismatch.

Fixes #71155
2026-10-20 13:36:55 -07:00
Matthieu Riegler fade609afd refactor(core): modernize unit tests across packages
Removes unnecessary `changeDetection: ChangeDetectionStrategy.Eager` from test components where default `OnPush` change detection works or where state updates can use signals, removes unnecessary `provideZoneChangeDetection()`, replaces `fixture.detectChanges()` with `await fixture.whenStable()` where appropriate, and cleans up redundant `forwardRef`/`CommonModule` imports and unused selectors.
2026-10-14 11:12:55 -07:00
Matthieu Riegler ecbc89b465 refactor(core): modernize unit tests across all packages
This should also help preventing agent from generating code that doesn't follow our latest guidelines.
2026-10-12 15:26:29 -07:00
arturovt fc3dc890aa fix(forms): don't crash when control is missing in setUpValidators
setUpValidators was reading control._rawValidators without checking
whether control even exists. If a directive's ngOnChanges fires
before its control is wired up (this can happen in some race
conditions), control is null or undefined, and it throws a raw
TypeError that doesn't tell you anything useful.

Added a check at the top: if control is null or undefined, throw a
proper RuntimeError (code 1003) instead. The check itself is always
on, not gated by ngDevMode, since the whole point is that this
happens in production builds, where the existing ngDevMode-only
guards get stripped out. The message text is still gated behind
ngDevMode though, the same way MISSING_CONTROL_VALUE (-1002) does.

Added a test that reproduces this with a real `@Component` using
[formGroup], where the form input is never set, so it goes through
Angular's actual change detection and lifecycle hooks instead of
just calling the function directly.
2026-10-06 12:58:54 -04:00
Shuaib Hasan Akib de47371baf refactor(forms): modernize value accessor integration tests
Migrate the value accessor integration spec to current Angular patterns:
- use standalone fixtures that import only the forms module they need,
  instead of declaring them through an `initTest` helper
- replace `*ngFor`/`*ngIf` with `@for`/`@if`
- use `inject()` instead of constructor injection

The reactive and template integration specs reuse two of these fixtures and
are updated to create them directly.
2026-10-05 12:09:32 -04:00
Jaime Burgos 8afd85c6d7 test(forms): migrate integration tests to zoneless scheduling
Use whenStable instead of manual change detection so integration tests exercise scheduled rendering. Await asynchronous callbacks and remove redundant timer waits to keep assertions within the test lifecycle.
2026-09-09 16:24:37 +02:00
Shuaib Hasan Akib 1bc7e3c2c3 refactor(core): use native Promise.withResolvers() in remaining tests
Replaces the remaining hand-rolled deferred promise implementations
with the native `Promise.withResolvers()` API and removes the now
unused helper and import.

Follow-up to #69739.
2026-09-09 16:17:04 +02:00
SkyZeroZx c235ecef8a test(forms): remove redundant change detection configuration
OnPush is now the default change detection strategy, and tests run zoneless by default, so the explicit configuration is no longer needed.
2026-09-09 16:13:08 +02:00
Kristiyan Kostadinov 732e505018 fix(core): replace all hasOwnProperty usages with Object.hasOwn
We keep getting PRs that target single usages of `hasOwnProperty` and we have ~100 of them. These changes aim to address the issue centrally by swapping out all the instances and adding a lint rule against introducing new ones.
2026-08-18 09:17:18 -07:00
arturovt 38d093232c fix(forms): warn in dev mode when ngModel cannot reach parent NgForm across component boundary
NgModel injects ControlContainer with @Host(), which stops the injector at
the component host element boundary. When NgForm lives in a parent component
and ngModel lives in a child component, the injection returns null silently
and the control acts standalone — never registering with the form.

To surface this invisible failure, emit a dev-mode warning (NG01354) when
ngModel's @Host() injection finds nothing but the element Injector can still
reach a ControlContainer further up the hierarchy. The warning identifies the
cross-boundary issue and points developers to the viewProviders fix or the
standalone option.

Adds the NG01354 reference page explaining why the warning fires and providing
two remediation paths: bridging ControlContainer via viewProviders, or opting
out with [ngModelOptions]="{standalone: true}".

Fixes #47580
2026-08-17 13:59:40 -07:00
splincode 9e37a58e14 fix(forms): keep radio inputs in sync when values change
Recompute the checked state when a reused radio input receives a new value while the form model remains unchanged.

Handle this case for both reactive forms and signal forms, and add regression tests covering reused radio elements.
2026-08-07 16:15:06 -07:00
SkyZeroZx 6deb6afcd1 refactor(forms): modernize reactive forms tests to rely on whenStable
Rely on zoneless scheduling throughout reactive forms tests instead of triggering change detection manually.
2026-07-30 09:06:29 -07:00
Matthieu Riegler f06b96d181 fix(forms): harden FormGroup control lookups against prototype shadowing
Guard FormGroup control-map presence checks with safe own-property checks to avoid inherited/prototype collisions from reserved keys such as hasOwnProperty and toString.

This prevents:
- crashes from shadowed hasOwnProperty access paths
- incorrect early-return and existence behavior for prototype-named controls

Adds regression tests for prototype-shadowed keys covering:
- register/add with toString
- contains/get with hasOwnProperty
- setControl/removeControl with toString
- FormRecord behavior with hasOwnProperty
2026-06-09 19:27:56 -07:00
Matthieu Riegler 7f3f3d7da1 ci: remove remainings of saucelabs tests
Those haven't been used for a while.
2026-04-22 14:41:03 -07:00
Matthieu Riegler eae8f7e30b feat(core): Set default Component changeDetection strategy to OnPush
The default change detection strategy is now OnPush.

BREAKING CHANGE: Component with undefined `changeDetection` property are now `OnPush` by default. Specify `changeDetection: ChangeDetectionStrategy.Eager` to keep the previous behavior.
2026-03-24 16:25:02 -07:00
Alex Rickabaugh c4ce3f345f feat(forms): template & reactive support for FVC
Implement support for `FormUiComponent`s in both Reactive and Template-driven
forms. This allows components that use the new signal-based form control
architecture to be used seamlessly within existing Angular form paradigms.

Key changes:
- Integrated `ɵngControlCreate` and `ɵngControlUpdate` lifecycle hooks into
  `NgModel`, `FormControlDirective`, and `FormControlName`.
- Implemented branching logic to choose between the traditional `ControlValueAccessor` (CVA) path and the new FVC path based on the host element's capabilities.
- Added comprehensive unit tests for FVC integration in both Reactive (`reactive_fvc.spec.ts`) and Template-driven (`template_fvc.spec.ts`) forms, covering:
    - Value synchronization (model -> view and view -> model).
    - Status synchronization (touched, dirty, valid, invalid, pending, required).
    - Error propagation and `parseErrors` support.
    - Fallback behavior to native DOM properties (disabled, required) when FVC inputs are missing.
    - Graceful fallback to CVA when no FVC pattern is detected.
- Refined `NgModel` to correctly handle `required` validation via its existing `RequiredValidator` directive while supporting FVC for other properties.
2026-03-17 13:18:26 -06:00
Matthieu Riegler 2061fd8253 fix(forms): Untrack setValue in reactive forms
Reasonably, writing to an `AbstractControl` shouldn't register signal reads.

fixes #67073
2026-02-19 09:11:06 -08:00
SkyZeroZx 19d0ceede3 test(forms): move timeout and autoTick helpers to shared testing utilities
Centralizes common test helpers under testing utilities and updates usages
2026-02-10 07:45:00 -08:00
Angular Robot 11767cabe4 build: update Jasmine to 6.0.0
Jasmine enables `forbidDuplicateNames: true` by default. So we also need to desambiguate duplicate spec names.
2026-02-09 12:15:57 -08:00
SkyZeroZx 7dfbacbcf8 test(forms): remove zone-based testing utilities
Removes usages of zone-based helpers such as `fakeAsync` , `tick`
`waitForAsync` as part of the migration to zoneless tests.

Completes the transition to zoneless.
2026-02-04 15:38:09 -08:00
SkyZeroZx 4aae3379c2 test(forms): migrate reactive forms and value accessors to zoneless
Migrates reactive forms, template-driven forms, and value accessors to zoneless tests.
2026-02-02 10:16:58 -08:00
SkyZeroZx f4469ad583 refactor(core): update error message links to versioned docs (#66374)
Error message links now point to the archived documentation site (v*.angular.dev)
so that referenced content matches the framework version in use.

See angular#44650

PR Close #66374
2026-01-09 22:33:51 +00:00
Matthieu Riegler 6270bba056 ci: reformat files
This is after we've slightly changed a rule in #66056
2025-12-16 14:44:19 -08:00
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