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/shortcuts.md.

LynxShortcuts

Hears the app's shortcuts: the things angular.json's shortcuts says the app does, which the person runs from Siri, Spotlight and the Shortcuts app on iOS, and from the app icon's menu on Android. import { LynxShortcuts, type LynxShortcut, type LynxShortcutHandler } from '@blotch/angular-lynx';

Add shortcuts for Siri and the app icon shows it in use.

Usage

angular.json
"shortcuts": [
  { "id": "refresh", "title": "Refresh", "phrases": ["Refresh {appName}"] },
  { "id": "photos", "title": "Show photos", "route": "/photos" }
]
export class Feed {
  readonly posts = resource({ loader: loadPosts });

  constructor() {
    inject(LynxShortcuts).on('refresh', () => this.posts.reload());
  }
}

API

LynxShortcuts

@Injectable({ providedIn: 'root' })
class LynxShortcuts {}
HostWhere the person runs a shortcut
iOS 16 and later (ng build --platform ios)Siri, Spotlight, the Shortcuts app and the Action button
Android 7.1 and later (ng build --platform android)The menu a long press on the app's icon opens
Web preview, Lynx ExplorerNowhere: no shortcut ever runs
Unit tests (testing library)runShortcut()

The phone brings the app to the front, starting it if it has to, and then the shortcut arrives here. A shortcut with a route makes the router navigate to it, when the app uses provideRouter() from @blotch/angular-lynx, and then its handlers are called. provideRouter() creates the service as the app starts, so a route needs no code.

LynxShortcuts.on()

on(
  id: string,
  handler: LynxShortcutHandler,
  options?: { readonly injector?: Injector },
): () => void;

Calls handler each time the person runs the shortcut id, the id it has in angular.json. Every handler registered for the ID is called, in the order they were registered. A handler that throws is reported to Angular's ErrorHandler, and the others are still called.

  • A shortcut nothing handled waits. One that ran before any handler was registered for its ID is kept for the first handler registered for it, which is called once the code that registered it has finished. That's how the shortcut that started the app reaches a component created later, such as the screen its route leads to.
  • The handler goes with its injection context. Called from one, such as a constructor, the handler is removed when the component or service is destroyed. Pass injector to tie it to another. Outside one, it stays until it's removed.
  • Returns a function that removes the handler.

LynxShortcut

type LynxShortcut = {
  readonly id: string;
  readonly route?: string;
};

type LynxShortcutHandler = (shortcut: LynxShortcut) => void;
FieldDescription
idThe shortcut's id in angular.json's shortcuts
routeIts route there, if it has one. The router has already been told to navigate to it

The shortcuts option

Each entry of the build target's shortcuts in angular.json:

FieldTypeDescription
idstringRequired. What on() knows it by. Letters, digits, hyphens and underscores, starting with a letter. Two IDs can't differ only by -/_ or capitals
titlestringRequired. The name the phone lists it under
phrasesstring[]What the person says to Siri. Each must contain {appName}, and no two shortcuts can share one. Defaults to ["<title> in {appName}"]. iOS only
routestringThe path the router navigates to, starting with /
symbolstringThe SF Symbol iOS draws beside it, such as arrow.clockwise. iOS only: Android draws the app's icon

iOS takes up to 10 shortcuts from an app. ng build --platform checks all of this and says what's wrong, and builds the shortcuts into the app: App Intents on iOS, static shortcuts on Android.