Elements
LYNX_ELEMENTS declares every Lynx element as an Angular directive, so your templates type-check. import { LYNX_ELEMENTS } from '@blotch/angular-lynx';
The rest of the element exports have pages of their own:
Usage
- Your editor's type checking and
ng testneed it.ng buildandng servedon't. See What the build checks. - Attributes are inputs. Each directive declares its element's attributes as inputs, so
[src]="url()"type-checks. Bind any other attribute with[attr.name]. - Events aren't outputs. Bind them by name, such as
(bindtap). Angular still types each one's$event: see Element events. Handling taps and events shows how to bind them.
What the build checks
In a component that doesn't import LYNX_ELEMENTS, ng build and ng serve still accept Lynx's elements and the attributes their directives declare.
They do report the rest of Angular's unknown-element and unknown-property errors (NG8001 and NG8002). For example:
- a component used in a template but left out of
imports - a mistyped input
On the phone, these would be a blank space, or a binding that goes nowhere.
- They're warnings with the code frame, and the build passes.
- The
elementChecksbuild option changes that."error"makes them errors, as inng test."off"leaves them out. - The build reads which elements and attributes to accept from
@blotch/angular-lynx's type declarations. If it can't find them, it warns and reports none of these errors, whateverelementCheckssays.
HTML tags and component hosts
The runtime renders some HTML tags as Lynx elements, such as div (a <view>), span (a <text>) and img (an <image>). In ng build, they take their element's attributes too: <div [accessibility-label]="label()"> builds without a warning.
The same goes for the attributes every element takes (accessibility-label, flatten, consume-slide-event, …) on a component's host and on canvas.
ng test and the editor don't know them there. In tested code, bind them with [attr.accessibility-label], or use the Lynx element.
Native elements of your own
Native elements that your app's iOS and Android code registers aren't in LYNX_ELEMENTS. To use one, either:
- give it a directive of your own that selects its tag and declares its attributes as inputs, as
LYNX_ELEMENTSdoes (seeLynxElementAttributes) - or add
CUSTOM_ELEMENTS_SCHEMAto theschemasof the components that use it
At runtime
Every element's directive except input's and textarea's only declares attributes. At runtime, Angular makes no directive for those elements: the renderer sets the attributes itself. That keeps a screen of many elements quick to build.
- So
viewChild(LynxView)finds nothing. To reach an element, give it a template reference:viewChild('card', { read: ElementRef }). - A directive of your own can take an element's attribute. If it declares the attribute as an input, it takes the binding, and the element doesn't get it. That's how a directive's input works on the web too.
- To give the element the attribute too, set it from your directive's
host:'[attr.accessibility-label]': 'label()'.
API
LYNX_ELEMENTS
Every directive below, as one array for a component's imports. Each directive is also exported on its own.
LynxIf and LynxFor
Declare Lynx's own low-level <if> and <for> elements, so a template that contains them type-checks.
- They're unrelated to Angular's
@ifand@forblocks. - AngularLynx doesn't test them. Use
@ifand@forinstead.
Attributes on every element
Every directive above also accepts these inputs, except:
- the two form accessors
LynxRouterLinkActive,LynxAccessibilityTraitsandLynxListFor
Write the true/false ones either way: flatten="false" and [flatten]="false" both give Lynx a boolean. The same goes for the numbers of pan-intercept-direction and pan-intercept-scope.
Types
BaseLynxElement
The nativeElement of an element's ElementRef. It's AngularLynx's wrapper around the native element, not a DOM element. Type an ElementRef with it to call its methods:
animate()starts an animation. See Animation.invoke()calls one of the element's UI methods, such asscrollTo. If you call it before the element is on screen, such as fromngAfterViewInit(), it waits until it is.focus()andblur()give an<input>or<textarea>the focus and take it away, as on the web. Focus opens the keyboard. Other elements have no focus, and nothing happens. Signal Forms'focusBoundControl()callsfocus().setAccessibilityTrait()adds a trait to the element's ownaccessibility-traits, or takes it away.LynxAccessibilityTraitsdoes the same from a template.
Related
- Elements and layout: which element to use, and how they differ from HTML.
- Handling taps and events
- Forms
- Accessibility and Exposure: the shared attributes in detail.
