# numAttr

> Input-transform factory: coerces any bound value to a number with a fallback. The standard transform for numeric inputs across ngwr.

Source: https://ngwr.dev/reference/utils/num-attr  
Kind: Util

## Usage

```angular-ts
import { numAttr } from 'ngwr/utils';

readonly speed = input(4, { transform: numAttr(4) });

// <wr-thing speed="12" />   → 12 (string attribute coerced)
// <wr-thing [speed]="x" />  → x ?? 4
```

## Why ngwr provides this

Angular's own `numberAttribute` falls back to `NaN`, which then needs guarding at every read. Wrapping `coerceNumberProperty` with a declared fallback keeps templates free to pass strings, numbers, or nothing — every numeric input in the kit uses it, so it's exported for app inputs too.

```angular-ts
// Angular built-in: NaN fallback leaks into your math.
readonly a = input(0, { transform: numberAttribute }); // 'abc' → NaN

// ngwr: declared fallback.
readonly b = input(4, { transform: numAttr(4) });      // 'abc' → 4
```

## API

| Name | Description | Type | Default |
| --- | --- | --- | --- |
| `numAttr` | Returns an input transform that coerces to number with a fallback. | `(fallback: number) => (value: unknown) => number` | `—` |
