API for coercion

API reference for Angular CDK coercion

Import symbols from @angular/cdk/coercion

coerceBooleanProperty

Coerces a data-bound value (typically a string) to a boolean.

Parameters

value

any

Returns
boolean

coerceNumberProperty
Parameters

value

any

fallbackValue

number = 0

coerceArray
Parameters

value

T | T[]

Returns
T[]

coerceCssPixelValue

Coerces a value to a CSS pixel value.

Parameters

value

any

Returns
string

coerceElement

Coerces an ElementRef or an Element into an element. Useful for APIs that can accept either a ref or the native element itself.

Parameters

elementOrRef

T | ElementRef<T>

Returns
T

coerceStringArray

Coerces a value to an array of trimmed non-empty strings. Any input that is not an array, null or undefined will be turned into a string via toString() and subsequently split with the given separator. null and undefined will result in an empty array. This results in the following outcomes:

  • null -> []
  • [null] -> ["null"]
  • ["a", "b ", " "] -> ["a", "b"]
  • [1, [2, 3]] -> ["1", "2,3"]
  • [{ a: 0 }] -> ["[object Object]"]
  • { a: 0 } -> ["[object", "Object]"]

Useful for defining CSS classes or table columns.

Parameters

value

any

the value to coerce into an array of strings

separator

string | RegExp = /\s+/

split-separator if value isn't an array

Returns
string[]

Coercion
Azure & Blue theme selected.