Skip to content

Commit

Permalink
refactor(forms): Provide RadioControlRegistry in root.
Browse files Browse the repository at this point in the history
The `RadioControlRegistry` was only provided in a module, providedIn: 'root' fixes that issue.

Fixes angular#54117

Co-authored-by: sr5434 <s98775763@gmail.com>
  • Loading branch information
JeanMeche and sr5434 committed Jan 29, 2024
1 parent fa0f44d commit a1a9f34
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@
{
"name": "REMOVE_STYLES_ON_COMPONENT_DESTROY"
},
{
"name": "RadioControlRegistryModule"
},
{
"name": "ReactiveFormsComponent"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,6 @@
{
"name": "REQUIRED_VALIDATOR"
},
{
"name": "RadioControlRegistryModule"
},
{
"name": "Renderer2"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/forms/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {NgModel} from './directives/ng_model';
import {NgModelGroup} from './directives/ng_model_group';
import {NgNoValidate} from './directives/ng_no_validate_directive';
import {NumberValueAccessor} from './directives/number_value_accessor';
import {RadioControlRegistryModule, RadioControlValueAccessor} from './directives/radio_control_value_accessor';
import {RadioControlValueAccessor} from './directives/radio_control_value_accessor';
import {RangeValueAccessor} from './directives/range_value_accessor';
import {FormControlDirective} from './directives/reactive_directives/form_control_directive';
import {FormControlName} from './directives/reactive_directives/form_control_name';
Expand Down Expand Up @@ -78,7 +78,6 @@ export const REACTIVE_DRIVEN_DIRECTIVES: Type<any>[] =
*/
@NgModule({
declarations: SHARED_FORM_DIRECTIVES,
imports: [RadioControlRegistryModule],
exports: SHARED_FORM_DIRECTIVES,
})
export class ɵInternalFormsSharedModule {
Expand Down
16 changes: 3 additions & 13 deletions packages/forms/src/directives/radio_control_value_accessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Directive, ElementRef, forwardRef, inject, Injectable, Injector, Input, NgModule, OnDestroy, OnInit, Provider, Renderer2, ɵRuntimeError as RuntimeError} from '@angular/core';
import {Directive, ElementRef, forwardRef, inject, Injectable, Injector, Input, OnDestroy, OnInit, Provider, Renderer2, ɵRuntimeError as RuntimeError} from '@angular/core';

import {RuntimeErrorCode} from '../errors';

import {BuiltInControlValueAccessor, ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor';
import {NgControl} from './ng_control';
import {CALL_SET_DISABLED_STATE, setDisabledStateDefault, SetDisabledStateOption} from './shared';
import {CALL_SET_DISABLED_STATE, setDisabledStateDefault} from './shared';

const RADIO_VALUE_ACCESSOR: Provider = {
provide: NG_VALUE_ACCESSOR,
Expand All @@ -27,21 +27,11 @@ function throwNameError() {
`);
}

/**
* Internal-only NgModule that works as a host for the `RadioControlRegistry` tree-shakable
* provider. Note: the `InternalFormsSharedModule` can not be used here directly, since it's
* declared *after* the `RadioControlRegistry` class and the `providedIn` doesn't support
* `forwardRef` logic.
*/
@NgModule()
export class RadioControlRegistryModule {
}

/**
* @description
* Class used by Angular to track radio buttons. For internal use only.
*/
@Injectable({providedIn: RadioControlRegistryModule})
@Injectable({providedIn: 'root'})
export class RadioControlRegistry {
private _accessors: any[] = [];

Expand Down
6 changes: 0 additions & 6 deletions packages/forms/src/form_providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import {CALL_SET_DISABLED_STATE, setDisabledStateDefault, SetDisabledStateOption
* Exports the required providers and directives for template-driven forms,
* making them available for import by NgModules that import this module.
*
* Providers associated with this module:
* * `RadioControlRegistry`
*
* @see [Forms Overview](/guide/forms-overview)
* @see [Template-driven Forms Guide](/guide/forms)
*
Expand Down Expand Up @@ -53,9 +50,6 @@ export class FormsModule {
* Exports the required infrastructure and directives for reactive forms,
* making them available for import by NgModules that import this module.
*
* Providers associated with this module:
* * `RadioControlRegistry`
*
* @see [Forms Overview](guide/forms-overview)
* @see [Reactive Forms Guide](guide/reactive-forms)
*
Expand Down

0 comments on commit a1a9f34

Please sign in to comment.