> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Bootstrap

Start an Angular app on Lynx and register the renderer that draws it. `import { bootstrapApplication, provideRenderer, loadLazyBundle } from '@blotch/angular-lynx';`

## Usage

```typescript title="src/main.ts"
import { bootstrapApplication } from '@blotch/angular-lynx';
import { App } from './app/app';
import { appConfig } from './app/app.config';

bootstrapApplication(App, appConfig);
```

```typescript title="src/app/app.config.ts"
import { type ApplicationConfig } from '@angular/core';
import { provideRenderer } from '@blotch/angular-lynx';

export const appConfig: ApplicationConfig = {
  providers: [provideRenderer()],
};
```

`ng add @blotch/angular-lynx` writes both files for you.

## API

### `bootstrapApplication()`

```typescript
function bootstrapApplication(
  rootComponent: Type<unknown>,
  options?: ApplicationConfig,
): Promise<ApplicationRef>;
```

Starts your app on Lynx. Use it instead of the `bootstrapApplication` from `@angular/platform-browser`, which needs a browser DOM.

- **Starts the app on the [main thread](/guide/glossary.md#main-thread)**, once Lynx is ready to render the page.
- **Starts nothing on the [background thread](/guide/glossary.md#background-thread).** That thread doesn't load your `main.ts`: it starts from an entry the build generates, with your background functions. If `main.ts` defines a background function itself, it loads there too, and the promise this returns there never settles, so code chained on it runs once. See [Threads](/guide/concepts/threads.md).
- **Hot reload.** Calling it again destroys the running app first, then starts the new one.
- **Returns** the `ApplicationRef`, as Angular's version does.

### `provideRenderer()`

```typescript
function provideRenderer(): EnvironmentProviders;
```

Registers the renderer that turns your templates into Lynx [elements](/guide/glossary.md#element). Every app needs it. Change detection needs no provider: without Zone.js, Angular is zoneless by default.

It also provides these Angular tokens:

| Token           | Value                                                                  | What it means for you                                                                                                                                                         |
| --------------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ErrorHandler`  | `LynxErrorHandler`                                                     | Uncaught errors go to Lynx. See [Errors and logging](/api/angular-lynx/errors-and-logging.md). To replace it, add your own `ErrorHandler` provider after `provideRenderer()`. |
| `DOCUMENT`      | A stub whose only method, `getElementById()`, returns `null`           | There's no DOM document. Don't query elements through `inject(DOCUMENT)`.                                                                                                     |
| `APP_BASE_HREF` | `'/'`                                                                  | The router's base path.                                                                                                                                                       |
| `IMAGE_CONFIG`  | `{ disableImageSizeWarning: true, disableImageLazyLoadWarning: true }` | Angular's image warnings scan the DOM and stop the app from starting. If you provide your own `IMAGE_CONFIG`, keep both flags `true`.                                         |

### `loadLazyBundle()`

```typescript
function loadLazyBundle(source: string): Promise<Type<unknown>>;
```

Loads a component from a separately built Lynx [bundle](/guide/glossary.md#bundle) at runtime.

| Parameter | Type     | Description                     |
| --------- | -------- | ------------------------------- |
| `source`  | `string` | URL of the `.lynx.bundle` file. |

- **Resolves** with the bundle's default export, or with all its exports when it has no default.
- **Caches** by `source`: repeat calls return the same promise.
- **On the background thread**, it rejects when the bundle fails to load or run.
- **On the main thread**, it loads synchronously. If loading fails, the promise never settles and the component doesn't appear.
- **Rejects** when Lynx's bundle loader isn't available, such as in unit tests.

```typescript title="src/app/app.routes.ts"
import type { Routes } from '@angular/router';
import { loadLazyBundle } from '@blotch/angular-lynx';

export const routes: Routes = [
  {
    path: 'profile',
    loadComponent: () =>
      loadLazyBundle('https://example.com/profile.lynx.bundle'),
  },
];
```

:::warning Experimental
Lazy routes with `import()` and `@defer` blocks don't need `loadLazyBundle()`. The build includes their code for you. These docs don't yet cover how to build a standalone component bundle.
:::

## Types

This page uses only Angular types: `ApplicationConfig`, `ApplicationRef`, `EnvironmentProviders` and `Type` from `@angular/core`.

## Related

- [Quick Start](/guide/quick-start.md): create an app that already has this setup.
- [How a Lynx app runs](/guide/concepts/how-it-runs.md)
- [Signals and change detection](/guide/concepts/signals.md): why the app must be zoneless.
- [Routing](/api/angular-lynx/routing/index.md): add `provideRouter()` next to `provideRenderer()`.
- [Errors and logging](/api/angular-lynx/errors-and-logging.md)
