diff --git a/goldens/public-api/forms/signals/index.api.md b/goldens/public-api/forms/signals/index.api.md index b7960c64717..44e38b1cb1c 100644 --- a/goldens/public-api/forms/signals/index.api.md +++ b/goldens/public-api/forms/signals/index.api.md @@ -10,6 +10,7 @@ import { ElementRef } from '@angular/core'; import { HttpResourceOptions } from '@angular/common/http'; import { HttpResourceRequest } from '@angular/common/http'; import * as i0 from '@angular/core'; +import { InjectionToken } from '@angular/core'; import { Injector } from '@angular/core'; import { InputSignal } from '@angular/core'; import { ModelSignal } from '@angular/core'; @@ -64,6 +65,9 @@ export interface ChildFieldContext extends RootFieldContext { readonly key: Signal; } +// @public +export const CONTROL: InjectionToken>; + // @public export class Control { get cva(): ControlValueAccessor | undefined; diff --git a/packages/forms/signals/src/api/control_directive.ts b/packages/forms/signals/src/api/control_directive.ts index 6e3e842118b..8ae9d996a08 100644 --- a/packages/forms/signals/src/api/control_directive.ts +++ b/packages/forms/signals/src/api/control_directive.ts @@ -15,6 +15,7 @@ import { ElementRef, EventEmitter, inject, + InjectionToken, Injector, Input, InputSignal, @@ -41,6 +42,13 @@ import {FormCheckboxControl, FormUiControl, FormValueControl} from './control'; import {AggregateProperty, MAX, MAX_LENGTH, MIN, MIN_LENGTH, PATTERN, REQUIRED} from './property'; import type {Field} from './types'; +/** + * Lightweight DI token provided by the {@link Control} directive. + */ +export const CONTROL = new InjectionToken>( + typeof ngDevMode !== undefined && ngDevMode ? 'CONTROL' : '', +); + /** * Binds a form `Field` to a UI control that edits it. A UI control can be one of several things: * 1. A native HTML input or textarea @@ -66,6 +74,10 @@ import type {Field} from './types'; provide: NgControl, useFactory: () => inject(Control).ngControl, }, + { + provide: CONTROL, + useExisting: Control, + }, ], }) export class Control {