# injectGridUndoRedo

Angular inject function for programmatic undo/redo control.

Uses **lazy grid discovery** - the grid element is found when methods are called,
not during initialization.

```ts
injectGridUndoRedo(selector: string): UndoRedoMethods
```

## Parameters

| Name | Type | Description |
| ---- | ---- | ----------- |
| `selector` | <code>string</code> | Optional CSS selector to target a specific grid element.
  Defaults to `'tbw-grid'` (first grid in the component). Use when the
  component contains multiple grids, e.g. `'tbw-grid.primary'` or `'#my-grid'`. |

#### Example

```typescript
import { Component } from '@angular/core';
import { Grid } from '@toolbox-web/grid-angular';
import '@toolbox-web/grid-angular/features/editing';
import '@toolbox-web/grid-angular/features/undo-redo';
import { injectGridUndoRedo } from '@toolbox-web/grid-angular/features/undo-redo';

@Component({
  selector: 'app-my-grid',
  imports: [Grid],
  template: `
    <button (click)="undoRedo.undo()" [disabled]="!undoRedo.canUndo()">Undo</button>
    <button (click)="undoRedo.redo()" [disabled]="!undoRedo.canRedo()">Redo</button>
    <tbw-grid [rows]="rows" [editing]="'dblclick'" [undoRedo]="true"></tbw-grid>
  `
})
export class MyGridComponent {
  undoRedo = injectGridUndoRedo();
}
```
