r/angular • • 22h ago

ng-origin: Alt+Click any element in your Angular dev app to copy which component declared it, with file and line

Side project I just released. You hold Alt (⌥ on Mac) in your dev app, click an element, and this goes to your clipboard:

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)

The idea is to paste that into a coding agent together with what you want, like "change this text" or "add a second button here". Agents usually find the spot on their own, but they search for it first, and that costs time and tokens. With the block they skip the search and go straight to the file.

Setup

npm i -D ng-origin, then provideNgOrigin() in your providers behind isDevMode(). Production builds drop the runtime.

Things you might ask

  • Privacy: no network requests, no storage. Form field values are never read. Secret-looking strings like JWTs or API keys get redacted, and you can add your own patterns. It's best-effort though, so look before you paste.
  • Versions: the peer range is Angular 20 to 22, but I've only tested 20.3, and only in Chromium. If you're on 21 or 22, I'd like to know if it works.
  • Why 22.0.0 as the first version: the major follows the newest Angular major it supports.
  • Template line: needs Angular 22.1.4+ with enableTemplateSourceLocations. Without it that line is left out.
  • i18n: ngx-translate keys come through ng-origin/ngx-translate. Other i18n libs can plug in their own lookup.

Page with a film (under a minute) · GitHub · MIT

If it names the wrong component somewhere in your app, I'd love an issue with the block it produced.

4 Upvotes

3 comments sorted by

1

u/AwesomeFrisbee 6h ago

Nice. I've mostly been using ng-inspect to get some details about a component (and mainly its current state) but its not really supported anymore and didn't really get an update with signals/standalone so its already a miracle that it still works.

Would be neat to get a new extension that includes a similar feature. I find that the current official Angular extension lacks ease of use for where I'm already looking in my devtools and find the page structure in the elements tab to make more sense to me. Not to mention easier to navigate and inspect other css stuff...

Regarding the ng-origin. Its kind of a shame it needs a provider to work. Would be neat if it worked on any angular app

0

u/abiramcodes 10h ago

We already have one called ng-point : https://abiramcodes.github.io/ng-point/

1

u/Old-Parsley-5826 10h ago edited 10h ago

Cool, very similar idea! I just tried it out, but it doesn't really work with library components and similar use cases. 🙈 ng-origin seems to cover all scenarios and also gaves you the main page component from the route, so I guess ng-point isn't really on point after all