For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /api/angular-lynx/bootstrap.md.

Bootstrap

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

Usage

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

bootstrapApplication(App, appConfig);
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()

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, once Lynx is ready to render the page.
  • Starts nothing on the 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.
  • Hot reload. Calling it again destroys the running app first, then starts the new one.
  • Returns the ApplicationRef, as Angular's version does.

provideRenderer()

function provideRenderer(): EnvironmentProviders;

Registers the renderer that turns your templates into Lynx elements. Every app needs it. Change detection needs no provider: without Zone.js, Angular is zoneless by default.

It also provides these Angular tokens:

TokenValueWhat it means for you
ErrorHandlerLynxErrorHandlerUncaught errors go to Lynx. See Errors and logging. To replace it, add your own ErrorHandler provider after provideRenderer().
DOCUMENTA stub whose only method, getElementById(), returns nullThere'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()

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

Loads a component from a separately built Lynx bundle at runtime.

ParameterTypeDescription
sourcestringURL 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.
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'),
  },
];
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.