# injectTransaction

Signature
`injectTransaction(store?: Store): (callback: (txn: Transaction) => any) => any`

valdres-angular
Batch updates — subscribers fire once

Returns a function that runs a callback as a [transaction](https://valdres.dev/guides/transactions) on the current store: all updates apply atomically and subscribers fire once at the end. The callback receives `{ set, get, reset, del, unset }`. Call it in an injection context (field initializer or constructor).

## Usage

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

const firstNameAtom = atom("")
const lastNameAtom = atom("")

@Component({
    selector: "reset-form",
    template: `<button (click)="clear()">Clear</button>`,
})
export class ResetForm {
    txn = injectTransaction()
    clear() {
        this.txn(({ reset }) => {
            reset(firstNameAtom)
            reset(lastNameAtom)
        })
    }
}
```

Pass a store to target one explicitly: `injectTransaction(myStore)`.

## See also

- [Transactions guide](https://valdres.dev/guides/transactions) — semantics, nesting, and performance
- [injectStore](https://valdres.dev/angular/injectStore) — access the current store
