# injectAtom

Signature
`injectAtom<T>(atom: Atom<T>): AtomSignal<T>`

valdres-angular
Subscribe to and update an atom's value

Returns an Angular `WritableSignal` that stays in sync with the atom. Reading the signal returns the current value, and calling `.set()` or `.update()` updates the atom. Also provides a `.reset()` method.

## Usage

```ts
import { Component } from "@angular/core"
import { atom } from "valdres"
import { injectAtom } from "valdres-angular"

const countAtom = atom(0)

@Component({
    selector: "app-counter",
    template: `
        <span>{{ count() }}</span>
        <button (click)="count.update(c => c + 1)">+</button>
        <button (click)="count.reset()">Reset</button>
    `,
})
export class CounterComponent {
    count = injectAtom(countAtom)
}
```

## Returns

`AtomSignal<T>` extends Angular's `WritableSignal<T>` with:

| Method        | Description                       |
| ------------- | --------------------------------- |
| `()`          | Read the current value            |
| `.set(value)` | Set a new value                   |
| `.update(fn)` | Update based on previous value    |
| `.reset()`    | Reset to the atom's default value |

## See also

- [injectValue](https://valdres.dev/angular/injectValue) — read-only signal
- [injectSetAtom](https://valdres.dev/angular/injectSetAtom) — write-only setter
- [injectResetAtom](https://valdres.dev/angular/injectResetAtom) — reset function
