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

# Pass data from your native app

Your native app can hand values to Angular. **InitData** goes to one LynxView when the native app opens your bundle. **GlobalData** is shared by every LynxView, and can change while the app runs. **Data processors** reshape InitData before Angular sees it.


|                | [InitData](/guide/glossary.md#initdata)                  | [GlobalData](/guide/glossary.md#globaldata) |
| -------------- | -------------------------------------------------------- | ------------------------------------------- |
| Sent           | When the native app opens the bundle, with updates later | Any time, to every LynxView                 |
| Typical values | A user ID, the item a screen should show                 | The theme, the language, safe-area insets   |
| Read it with   | `LynxInitData`                                           | `LynxGlobalData`                            |

This page involves native code, like the rest of [Embedding](/guide/embedding/index.md).

## Read InitData

```typescript title="src/app/app.ts"
import { Component, computed, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxInitData } from '@blotch/angular-lynx';

@Component({
  selector: 'app-root',
  imports: [LYNX_ELEMENTS],
  template: `<text>User: {{ userId() }}</text>`,
})
export class App {
  readonly #initData = inject(LynxInitData);
  readonly userId = computed(
    () => this.#initData.initData()['userId'] ?? 'guest',
  );
}
```

- **`initData()`** is a signal holding the whole object.
- **Give each field a fallback.** `initData()` is `{}` when no native app sent any, such as in Lynx Explorer or the web preview.
- **No setup.** `LynxInitData` is provided in the root injector.

## Read GlobalData

```typescript title="src/app/banner.ts"
import { Component, computed, inject } from '@angular/core';
import { LYNX_ELEMENTS, LynxGlobalData } from '@blotch/angular-lynx';

@Component({
  selector: 'app-banner',
  imports: [LYNX_ELEMENTS],
  template: `<text>Platform: {{ platform() }}</text>`,
})
export class Banner {
  readonly #globalData = inject(LynxGlobalData);
  readonly platform = computed(
    () => this.#globalData.globalData()['platform'] ?? 'unknown',
  );
}
```

`globalData()` is an empty object when the native app sends no GlobalData. For the theme and the language, use the services in [Theme and language](#theme-and-language) instead.

## Send the data from native code

Your native app sends InitData when it loads the bundle into a LynxView, and GlobalData whenever it likes.

On iOS, in Swift:

```swift
let initData = LynxTemplateData(dictionary: ["userId": "user_42"])
lynxView.updateGlobalProps(with: LynxTemplateData(dictionary: ["theme": "Dark"]))
lynxView.loadTemplate(fromURL: bundleUrl, initData: initData)

// Later:
lynxView.updateData(with: ["userId": "user_43"])
```

On Android, in Kotlin:

```kotlin
lynxView.updateGlobalProps(mapOf<String, Any>("theme" to "Dark"))
lynxView.renderTemplateUrl(bundleUrl, mapOf<String, Any>("userId" to "user_42"))

// Later:
lynxView.updateData(mapOf<String, Any>("userId" to "user_43"))
```

- **Lynx calls GlobalData "global props"**, hence `updateGlobalProps`.
- **Updates show up right away.** `updateData` merges the fields you send into the current InitData, and `initData()` changes to match. `updateGlobalProps` does the same for `globalData()`, and for the theme and language services.
- **Set GlobalData before loading the bundle,** so it's there when your app starts.
- **Newer Lynx APIs** load bundles with a `LynxLoadMeta` object instead. Lynx's [Using Data from Host Platform](https://lynxjs.org/guide/use-data-from-host-platform) guide shows them.

## Reshape InitData with data processors

A **data processor** is a function that turns the data the native app sends into the shape your app wants. Register processors in `main.ts`, before `bootstrapApplication()`:

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

registerDataProcessors({
  // Runs on InitData unless the native code names another processor.
  // Here it renames the native app's `user_id` field.
  defaultDataProcessor: (raw) => ({
    userId: String(raw['user_id'] ?? 'guest'),
  }),
  // Run only when the native code names them.
  dataProcessors: {
    refreshFeed: (data) => ({ ...data, feedRefreshed: true }),
  },
});

bootstrapApplication(App, appConfig);
```

- **Register before bootstrapping,** so the first data that arrives is already processed.
- **Named processors** run when native code names one in an update: `updateData(with: data, processorName: "refreshFeed")` in Swift, or `updateData(data, "refreshFeed")` in Kotlin.
- **A processor that throws** gives `{}` instead of crashing the app.

## Fake the data while developing

While you develop in Lynx Explorer or the web preview, no native app sends your app its data. Fill in sample values yourself in `main.ts`, before `bootstrapApplication()`:

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

// InitData: start from sample values, and let real ones win.
registerDataProcessors({
  defaultDataProcessor: (raw) =>
    isDevMode() ? { userId: 'user_42', ...raw } : raw,
});

// GlobalData: LynxGlobalData reads it when it's created.
if (isDevMode() && typeof lynx !== 'undefined') {
  const host = lynx as any;
  host.__globalProps = { theme: 'Dark', ...host.__globalProps };
}

bootstrapApplication(App, appConfig);
```

- **Fake InitData in a data processor.** Lynx hands your app its InitData as the page starts, which replaces anything you set on `lynx`. The processor runs on that data first.
- **Set GlobalData before bootstrapping,** because `LynxGlobalData` reads it when it's created.
- **`isDevMode()` is `false` in production builds,** so the fake values never ship.
- **The spread keeps real values,** if a native app does send some.

The [data-flow example](/examples/data-flow.md) sets fake values the same way, in its `src/main.ts`.

## What the generated apps pass

The apps `ng build --platform` makes are host apps too. They pass:

| Value                                                            | What it is                                                                                                                                                                                                                                                                     |
| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `platform`                                                       | `'ios'` or `'android'`                                                                                                                                                                                                                                                         |
| `theme`                                                          | `'Dark'` or `'Light'`, sent again whenever the phone switches                                                                                                                                                                                                                  |
| `appLocale`                                                      | The phone's language, such as `'fr-FR'`                                                                                                                                                                                                                                        |
| `appTimeZone`                                                    | The phone's time zone, such as `'Europe/Paris'`, which names the zone `Intl.DateTimeFormat` formats in by default when the build adds it (see [Use `Intl`](/guide/i18n/intl.md))                                                                                               |
| `isNotchScreen`                                                  | `true` on a screen with a notch, Dynamic Island or camera cutout                                                                                                                                                                                                               |
| `edgeToEdge`                                                     | `true` when the page fills the screen, as it does unless `angular.json` sets `"edgeToEdge": false`. CSS `env(safe-area-inset-*)` then gives the insets below. See [Safe area](/guide/safe-area.md)                                                                             |
| `safeAreaTop`, `safeAreaBottom`, `safeAreaLeft`, `safeAreaRight` | The safe-area insets, in the same units as CSS pixels: the part of the page the status bar, the home indicator and the camera cutout cover, sent again when they change. With `edgeToEdge` false, the window's, which the page sits inside                                     |
| `osVersion`                                                      | The OS version, such as `'26.1'`, which [`LynxSystemInfo`](/api/angular-lynx/device/system-info.md#lynxsysteminfoosversion) can't otherwise read in time                                                                                                                       |
| `reduceMotion`, `reduceTransparency`, `increaseContrast`         | The user's display settings, sent again when they change. See [`LynxAccessibilitySettings`](/api/angular-lynx/accessibility.md#lynxaccessibilitysettings). Android sends no `reduceTransparency`                                                                               |
| `textScale`                                                      | The user's text size as a number, `1` at the default (Dynamic Type on iOS, the font size on Android), sent again when it changes. The LynxView's font scale is set to the same number. See [Follow the phone's text size](/guide/accessibility.md#follow-the-phones-text-size) |
| `appState`                                                       | `'active'`, `'inactive'` or `'background'`, sent again as the app leaves the screen and comes back. See [`LynxAppState`](/api/angular-lynx/device/app-state.md)                                                                                                                |
| `online`                                                         | `true` while the phone has a connection to the internet, sent again when it changes. See [`LynxNetwork`](/api/angular-lynx/device/network.md)                                                                                                                                  |
| `screenWidth`, `screenHeight`, `viewportWidth`, `viewportHeight` | The app window's size and the page's, in the same units as CSS pixels, sent again when they change: a phone folding or unfolding, a rotation, split screen. See [`LynxViewport`](/api/angular-lynx/device/viewport.md) and [Adaptive layouts](/guide/adaptive-layouts.md)      |
| `dynamicColors`                                                  | Android 12 and later only: the wallpaper's colors, sent again when the user changes them. See [`LynxTheme.dynamicColors`](/api/angular-lynx/device/theme.md#lynxthemedynamiccolors)                                                                                            |

They pass no InitData.

To pass anything else, [eject](/guide/native-apps/eject.md) or [embed the app in your own](/guide/embedding/index.md).

## Theme and language

Two GlobalData values have services of their own. Use them instead of reading `globalData()`:

- **[`LynxTheme`](/api/angular-lynx/device/theme.md)** reads `theme`, `'Dark'` or `'Light'`, and defaults to `'Light'`. See [Dark mode](/guide/dark-mode.md). It reads `dynamicColors` too.
- **[`LynxLocale`](/api/angular-lynx/device/locale.md)** reads `appLocale`. It falls back to the `sourceLocale` in `angular.json`, then to `'en-US'`. See [Internationalization](/guide/i18n/index.md).

They apply those defaults and check the values for you. Have your native app send `theme` and `appLocale` under exactly those names.

## Type the data

By default, `initData()` and `globalData()` are typed as `Record<string, unknown>`. Describe your fields with [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation):

```typescript title="src/lynx-data.d.ts"
// This export makes the file a module, so the block below adds to
// @blotch/angular-lynx's types instead of replacing them.
export {};

declare module '@blotch/angular-lynx' {
  interface InitData {
    userId: string;
  }
  interface GlobalData {
    theme: 'Dark' | 'Light';
    appLocale: string;
  }
  // The data as native code sends it, before your data processor runs.
  interface InitDataRaw {
    user_id: string;
  }
}
```

Now `initData().userId` is a `string`, with no casting.

## Related

- [Embed in an existing native app](/guide/embedding/index.md)
- [Host data API](/api/angular-lynx/host/host-data.md): `LynxInitData`, `LynxGlobalData` and `registerDataProcessors()`.
- [Dark mode](/guide/dark-mode.md) and [Internationalization](/guide/i18n/index.md)
- [Using Data from Host Platform](https://lynxjs.org/guide/use-data-from-host-platform) on lynxjs.org
