Alt+Click any element in your Angular app and hand its origin to your coding agent

2026-12-04来源 dev.toEnglish
Alt+Click any element in your Angular app and hand its origin to your coding agent

Telling a coding agent which button you mean is weirdly hard. "The Archive button on the dashboard" sends it grepping for the label. In an app with a shared UI library it often ends up in the button component itself, not in the template where that particular button is declared.

ng-origin is a side project of mine that tries to fix this. Hold Alt (⌥ on a Mac) in your running dev app, click an element, and a plain-text block with its origin lands in your clipboard. Version 22.0.0 is the first release.

ng-origin tour, under a minute

What gets copied

For the Archive button in a dashboard widget, the block looks like this:

Page: /dashboard · route dashboard → DashboardPage (src/app/dashboard/dashboard-page.ts:13) Element: <button> "Archive" Inside: UiButton <button ui-button> (ui-kit) · variant=primary Declared in: Widget (src/app/widget/widget.ts:15) Projected into: CardShell (src/app/card-shell/card-shell.ts:13) Template: src/app/widget/widget.html:2 Find: widget.archive Chain: Widget > DashboardPage Context: lang=en · viewport=1440×900 (xl) 

Declared in is the line I care about most. It names the app component whose template contains the button, with file and line. The library component (UiButton) and the card the button is projected into get their own lines, so they don't get mixed up with it. Find collects search anchors: translation keys, your app's CSS class, data-testid. Every value is read from the running app. Nothing is guessed.

Paste that into your agent, add "make this a secondary button", and it starts in the right file.

Setup

npm i -D ng-origin 
// app.config.ts import { ApplicationConfig, isDevMode } from '@angular/core'; import { provideNgOrigin } from 'ng-origin'; export const appConfig: ApplicationConfig = { providers: [isDevMode() ? [provideNgOrigin()] : []], }; 

NgModule apps put the same provider into the root module. Every option is optional. appPrefixes tells it which CSS classes are yours, libraries maps selector prefixes like ui- to a package name, and there are breakpoints, a context callback (current role, language, whatever helps) and extra redact patterns.

With ngx-translate you get the translation keys through a ready-made resolver:

import { ngxTranslateTextKeys } from 'ng-origin/ngx-translate'; provideNgOrigin({ textKeys: ngxTranslateTextKeys() }); 

It compares the element's text with the translations already loaded for the current language, {{param}} placeholders included.

The Template line needs Angular 22.1.4 or later with enableTemplateSourceLocations in a development tsconfig. Without it, that one line is left out.

Small things that matter

  • The click never reaches the app. No handler runs, nothing navigates, focus stays where it was.
  • Alt+Shift+Click appends a block to the last one, so you can hand over a few elements at once.
  • Some Linux window managers grab Alt+Click to move windows. modifier: 'ctrl-shift' switches to Ctrl+Shift+Click.
  • window.ngOrigin.describe(element) returns the block without copying it, which is handy in Playwright tests.

Privacy and production

ng-origin makes no network requests and writes no storage. A block leaves the page only through your clipboard. Input values and the text of form fields are never read, and secret-shaped strings such as JWTs or API keys are replaced with «redacted» before anything is copied. That part is best-effort, so read a block before you paste it somewhere you don't trust.

Production builds drop the runtime and its strings. In dev it loads lazily as its own chunk after bootstrap.

Limits

So far only Chromium is tested, and only with a mouse. The peer range allows Angular 20 to 22, but my tests run on 20.3. It also relies on Angular's dev-mode debug API (window.ng), which can change between majors.

Why the first release is 22.0.0

The major follows Angular. It's the newest Angular major ng-origin supports, so Angular 23 will bring ng-origin 23, and breaking changes wait for it.

Code and docs are on GitHub, the package is on npm, MIT licensed. If you're on Angular 21 or 22, I'd really like to hear whether it works for you.

原文:https://www.a8q9.cn/en/article/alt-click-any-element-in-your-angular-app-and-hand-its-origin-to-your-coding-age-0d5325.html

相关文章