@@ -18,7 +18,7 @@ export function inputFunction<ReadT, WriteT>(
1818 return createInputSignal ( initialValue , opts ) ;
1919}
2020
21- export function inputRequiredFunction < ReadT , WriteT > ( opts ?: InputOptions < ReadT , WriteT > ) :
21+ export function inputRequiredFunction < ReadT , WriteT = ReadT > ( opts ?: InputOptions < ReadT , WriteT > ) :
2222 InputSignalWithTransform < ReadT , WriteT > {
2323 ngDevMode && assertInInjectionContext ( input ) ;
2424 return createInputSignal ( REQUIRED_UNSET_VALUE as never , opts ) ;
@@ -31,77 +31,95 @@ export function inputRequiredFunction<ReadT, WriteT>(opts?: InputOptions<ReadT,
3131 * The function exposes an API for also declaring required inputs via the
3232 * `input.required` function.
3333 *
34- * @usageNotes
35- * Initialize an input in your directive or component by declaring a
36- * class field and initializing it with the `input()` or `input.required()`
37- * function.
38- *
39- * ```ts
40- * @Directive({..})
41- * export class MyDir {
42- * firstName = input<string>(); // string|undefined
43- * lastName = input.required<string>(); // string
44- * age = input(0); // number
45- * }
46- * ```
47- *
4834 * @developerPreview
4935 */
5036export interface InputFunction {
5137 /**
52- * Initializes an input with an initial value. If no explicit value
53- * is specified, Angular will use `undefined`.
54- *
55- * Consider using `input.required` for inputs that don't need an
56- * initial value.
38+ * Initializes an input of type `T` with an initial value of `undefined`.
39+ * Angular will implicitly use `undefined` as initial value.
40+ */
41+ < T > ( ) : InputSignal < T | undefined > ;
42+ /** Declares an input of type `T` with an explicit initial value. */
43+ < T > ( initialValue : T , opts ?: InputOptionsWithoutTransform < T > ) : InputSignal < T > ;
44+ /**
45+ * Declares an input of type `T` with an initial value and a transform
46+ * function.
5747 *
58- * @developerPreview
48+ * The input accepts values of type `TransformT` and the given
49+ * transform function will transform the value to type `T`.
5950 */
60- < ReadT > ( ) : InputSignal < ReadT | undefined > ;
61- < ReadT > ( initialValue : ReadT , opts ?: InputOptionsWithoutTransform < ReadT > ) : InputSignal < ReadT > ;
62- < ReadT , WriteT > ( initialValue : ReadT , opts : InputOptionsWithTransform < ReadT , WriteT > ) :
63- InputSignalWithTransform < ReadT , WriteT > ;
51+ < T , TransformT > ( initialValue : T , opts : InputOptionsWithTransform < T , TransformT > ) :
52+ InputSignalWithTransform < T , TransformT > ;
6453
6554 /**
6655 * Initializes a required input.
6756 *
68- * Users of your directive/component need to bind to this
57+ * Consumers of your directive/component need to bind to this
6958 * input. If unset, a compile time error will be reported.
7059 *
7160 * @developerPreview
7261 */
7362 required : {
74- < ReadT > ( opts ?: InputOptionsWithoutTransform < ReadT > ) : InputSignal < ReadT > ;
75-
76- < ReadT , WriteT > ( opts : InputOptionsWithTransform < ReadT , WriteT > ) :
77- InputSignalWithTransform < ReadT , WriteT > ;
63+ /** Declares a required input of type `T`. */
64+ < T > ( opts ?: InputOptionsWithoutTransform < T > ) : InputSignal < T > ;
65+ /**
66+ * Declares a required input of type `T` with a transform function.
67+ *
68+ * The input accepts values of type `TransformT` and the given
69+ * transform function will transform the value to type `T`.
70+ */
71+ < T , TransformT > ( opts : InputOptionsWithTransform < T , TransformT > ) :
72+ InputSignalWithTransform < T , TransformT > ;
7873 } ;
7974}
8075
8176/**
82- * The `input` function allows declaration of inputs in directives and
83- * components.
77+ * The `input` function allows declaration of Angular inputs in directives
78+ * and components.
79+ *
80+ * There are two variants of inputs that can be declared:
8481 *
85- * Initializes an input with an initial value. If no explicit value
86- * is specified, Angular will use `undefined` .
82+ * 1. **Optional inputs** with an initial value.
83+ * 2. **Required inputs** that consumers need to set .
8784 *
88- * Consider using `input.required` for inputs that don't need an
89- * initial value.
85+ * By default, the `input` function will declare optional inputs that
86+ * always have an initial value. Required inputs can be declared
87+ * using the `input.required()` function.
88+ *
89+ * Inputs are signals. The values of an input are exposed as a `Signal`.
90+ * The signal always holds the latest value of the input that is bound
91+ * from the parent.
9092 *
9193 * @usageNotes
92- * Initialize an input in your directive or component by declaring a
93- * class field and initializing it with the `input()` function.
94+ * To use signal-based inputs, import `input` from `@angular/core`.
95+ *
96+ * ```
97+ * import {input} from '@angular/core`;
98+ * ```
99+ *
100+ * Inside your component, introduce a new class member and initialize
101+ * it with a call to `input` or `input.required`.
94102 *
95103 * ```ts
96- * @Directive({..})
97- * export class MyDir {
98- * firstName = input<string>(); // string|undefined
99- * lastName = input.required<string>(); // string
100- * age = input(0); // number
104+ * @Component({
105+ * ...
106+ * })
107+ * export class UserProfileComponent {
108+ * firstName = input<string>(); // Signal<string|undefined>
109+ * lastName = input.required<string>(); // Signal<string>
110+ * age = input(0) // Signal<number>
101111 * }
102112 * ```
103113 *
114+ * Inside your component template, you can display values of the inputs
115+ * by calling the signal.
116+ *
117+ * ```html
118+ * <span>{{firstName()}}</span>
119+ * ```
120+ *
104121 * @developerPreview
122+ * @initializerApiFunction
105123 */
106124export const input : InputFunction = ( ( ) => {
107125 // Note: This may be considered a side-effect, but nothing will depend on
0 commit comments