Coming from web Angular
This page lists everything that changes when you move Angular code from the browser to Lynx. Skim the cheat sheet first, then check the compatibility table for the features you use.
Cheat sheet
Your web templates render
AngularLynx renders common HTML tags as the Lynx element they stand for, so a template written for the browser shows up on a phone:
- Block tags render as a
<view>:<div>,<section>,<ul>,<li>and the like. - Text tags render as a
<text>:<span>,<p>,<h1>,<a>,<button>,<label>and the like. <img>renders as an<image>that takes its picture's size until CSS gives it one.- Text flows and inherits. Text and inline tags beside each other share a line, and take their ancestors' text styles.
- DOM events that Lynx also sends run, such as
(click),(input)and(keyup.enter).
It gets ported code on screen, but it isn't a browser. HTML tags lists what carries over and what doesn't. Write Lynx elements in new code: they have every attribute, and typed events.
Here's one component in each:
Templates
Lynx elements replace HTML. A Lynx app has no HTML engine. Lynx elements map to native UI controls instead, and AngularLynx renders common HTML tags as the closest one. Elements and layout lists them all.
Text belongs in <text>. On the web, text can sit anywhere. On Lynx, only a <text> draws it. Text written straight in a <view> or <div> still shows: AngularLynx draws it, and the inline tags beside it, in a <text>, which takes the text styles its ancestors' classes set. A <text> you write yourself inherits only its font size, so set its other styles on it, and nest <text> elements to style part of a sentence.
Import LYNX_ELEMENTS. Add it to every component that uses Lynx elements, as ng generate component does. It gives you type checking in your editor and makes ng test compile.
Events
DOM event names work where Lynx sends the same event. (click) runs on a tap and bubbles up to parent elements, as on the web, and $event.stopPropagation() stops it. (input) runs when the text changes, and (keyup.enter) when the keyboard's return key is pressed. A text field's value is in $event.target.value, as on the web. Pointer events, and the mouse events that say a pointer is over an element, such as (mouseenter), come from touches. Names Lynx has no event for, such as (keydown), never run.
Lynx's own event names start with bind or catch, and cover the events the DOM has no name for, such as (bindlongpress) and (bindscroll):
(bindtap)handles a tap and lets it bubble up, as(click)does.(catchtap)handles a tap and stops it there, with no code.
Lynx's own data is in $event.detail. A text input's value, for example, is $event.detail.value.
A handler can do anything it would on the web, such as navigate or open an overlay.
See Handling taps and events for every event.
Styling
Lynx has its own CSS engine. It supports most layout CSS, but its defaults differ from a browser's:
- Elements stack vertically by default (
display: linear). Adddisplay: flex(Tailwind'sflex) for flexbox. box-sizingisborder-box, and margins don't collapse.- Only
font-sizeis inherited. Afont-sizeon a<view>reaches the<text>inside it, but acolorthere doesn't color it. remis 14px, not 16px. The UI components' theme makes it 16px.- Some features are missing:
:hover,::beforeand!important.@mediaworks, against the page's size.
CSS on Lynx covers every difference. Tailwind CSS 4 works as on the web: the build adapts its CSS for Lynx.
The JavaScript environment
Your code doesn't run in a browser. There's no DOM, so document.querySelector and localStorage don't exist, and document.createElement makes only canvases and images that aren't shown. AngularLynx fills in what Angular itself needs, such as setTimeout and URL, and document: and window: listeners hear touches anywhere on screen.
To share stores and services with a web app, keep them in a library that TypeScript checks against what Lynx has: see Share code with an Angular web app.
Libraries that touch the DOM, or depend on browser APIs, won't work. That includes Angular Material and most of the CDK. Libraries that draw on a <canvas> work: chart and image libraries with its 2D context, and 3D libraries that draw with WebGL2, such as three.js and angular-three. The JavaScript environment lists what's available.
Angular feature compatibility
✅ works as on the web · ⚠️ works with differences · ❌ not supported
Related
- What is AngularLynx?
- Glossary: Lynx and mobile terms in plain words.
