# injectGridSelection

Angular inject function for programmatic selection control.

Uses **lazy grid discovery** - the grid element is found when methods are called,
not during initialization. This ensures it works reliably with:
- Lazy-rendered tabs
- Conditional rendering (*ngIf)
- Dynamic component loading

```ts
injectGridSelection(selector: string): SelectionMethods<TRow>
```

## 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/selection';
import { injectGridSelection } from '@toolbox-web/grid-angular/features/selection';

@Component({
  selector: 'app-my-grid',
  imports: [Grid],
  template: `
    <button (click)="handleSelectAll()">Select All</button>
    <tbw-grid [rows]="rows" [selection]="'range'"></tbw-grid>
  `
})
export class MyGridComponent {
  selection = injectGridSelection();

  handleSelectAll() {
    this.selection.selectAll();
  }

  getSelectedRows() {
    const selection = this.selection.getSelection();
    if (!selection) return [];
    // Derive rows from selection.ranges as needed
  }
}
```
