The JavaScript environment
Your app's JavaScript runs in Lynx's engine, not in a browser. Standard JavaScript works, but browser APIs mostly don't. This page lists what's there, what's missing, and what to use instead.
What AngularLynx adds for you
Lynx doesn't provide some APIs that Angular relies on. AngularLynx adds them before your app starts:
setTimeout,setInterval,clearTimeout,clearIntervalrequestAnimationFrame,requestIdleCallbackqueueMicrotask,AbortControllerURL,URLSearchParams
It also adds small document, window and navigator objects, with only what Angular reads internally. They are not a DOM: document.querySelector() always returns null.
What's missing, and what to use instead
Code that calls a missing API throws when it runs. That includes code inside libraries. Before adding an npm package, check that it doesn't use the DOM.
Network requests
Lynx provides fetch only on the background thread. Your components draw the UI and handle events on the main thread, which has no network access.
As a result, HTTP requests from Angular code aren't supported yet. That covers HttpClient, httpResource and calling fetch directly. Lynx itself has no XMLHttpRequest or WebSocket.
Two ways to load data today:
- Ship data in the app. Import JSON files, and they're built into the bundle.
- Call your native code. A host app you control can expose a networking module. Call it with
LynxNativeModule.
Timers
setTimeout and the other timer functions work. When the user switches to another app, Lynx pauses JavaScript, so a timer can fire late after the app comes back. Don't use timers to measure elapsed time; compare Date.now() values instead.
Storage
There's no localStorage. To share values between the pages of your app while it runs, use LynxSessionStorage. To keep data after the app closes, store it in the host app and reach it through a native module.
Intl
Lynx has no Intl object. Libraries that call Intl.DateTimeFormat, Intl.NumberFormat or Intl.PluralRules throw on Lynx. Add the FormatJS polyfills for the parts you use. Internationalization shows the setup.
Angular's own pipes, such as DatePipe and CurrencyPipe, use Angular's locale data instead of Intl, so they work.
URL
URL and URLSearchParams work, because AngularLynx provides them. There's no window.location and no address bar: the router keeps its URL in memory. See Routing.
JavaScript language level
Write modern TypeScript as usual. The build compiles new syntax, such as ?. and ??, down to what Lynx supports.
The build doesn't add missing built-in methods. The main thread supports ES2019, so these newer methods are missing there:
If a template or a computed() calls a missing method, the render fails, and nothing on screen updates. The error is "not a function". It's not about signals.
Related
- Coming from web Angular
- Threads: where your code runs
- Debugging: how to see errors like these.
