• Overview
@angular/core

input

Initializer API

The input function allows declaration of Angular inputs in directives and components.

There are two variants of inputs that can be declared:

  1. Optional inputs with an initial value.
  2. Required inputs that consumers need to set.

By default, the input function will declare optional inputs that always have an initial value. Required inputs can be declared using the input.required() function.

Inputs are signals. The values of an input are exposed as a Signal. The signal always holds the latest value of the input that is bound from the parent.

  
    
  
  
function input<T>(): InputSignal<T | undefined>;

Initializes an input of type T with an initial value of undefined. Angular will implicitly use undefined as initial value.

@returnsInputSignal<T | undefined>
function input<T>(initialValue: T, opts?: InputOptionsWithoutTransform<T> | undefined): InputSignal<T>;

Declares an input of type T with an explicit initial value.

@paraminitialValueT
@paramoptsInputOptionsWithoutTransform<T> | undefined
@returnsInputSignal<T>
function input<T>(initialValue: undefined, opts: InputOptionsWithoutTransform<T>): InputSignal<T | undefined>;

Declares an input of type T|undefined without an initial value, but with input options

@paraminitialValueundefined
@returnsInputSignal<T | undefined>
function input<T, TransformT>(initialValue: T, opts: InputOptionsWithTransform<T, TransformT>): InputSignalWithTransform<T, TransformT>;

Declares an input of type T with an initial value and a transform function.

The input accepts values of type TransformT and the given transform function will transform the value to type T.

@paraminitialValueT
@paramoptsInputOptionsWithTransform<T, TransformT>
@returnsInputSignalWithTransform<T, TransformT>
function input<T, TransformT>(initialValue: undefined, opts: InputOptionsWithTransform<T | undefined, TransformT>): InputSignalWithTransform<T | undefined, TransformT>;

Declares an input of type T|undefined without an initial value and with a transform function.

The input accepts values of type TransformT and the given transform function will transform the value to type T|undefined.

@paraminitialValueundefined
@paramoptsInputOptionsWithTransform<T | undefined, TransformT>
@returnsInputSignalWithTransform<T | undefined, TransformT>
function input.required<T>(opts?: InputOptionsWithoutTransform<T> | undefined): InputSignal<T>;

Declares a required input of type T.

@paramoptsInputOptionsWithoutTransform<T> | undefined
@returnsInputSignal<T>
function input.required<T, TransformT>(opts: InputOptionsWithTransform<T, TransformT>): InputSignalWithTransform<T, TransformT>;

Declares a required input of type T with a transform function.

The input accepts values of type TransformT and the given transform function will transform the value to type T.

@paramoptsInputOptionsWithTransform<T, TransformT>
@returnsInputSignalWithTransform<T, TransformT>
Jump to details