October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

NG2009: Invalid Shadow DOM selector in Angular and How to Fix It

NG2009 means a component using ViewEncapsulation.ShadowDom has a selector that is not a valid custom element name. Rename it to lowercase, hyphenated form, such as app-comp.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

NG2009 is an Angular compiler error raised when a component that uses ViewEncapsulation.ShadowDom has a selector that is not a valid custom element tag name. The fix is to rename the selector so it meets those naming rules. Angular’s own example changes comp to app-comp.

What the error means

Angular’s official error page for NG2009 gives the plain-language cause: “The selector of a component using ViewEncapsulation.ShadowDom doesn’t match the custom element tag name requirements.” Angular: NG2009 — Invalid Shadow DOM selector is the primary reference, and the title it uses is “Invalid Shadow DOM selector,” classified as a compiler error in the Angular Error Encyclopedia.

As an Amazon Associate I earn from qualifying purchases.

The error is about the component’s selector, not about the shadow DOM feature itself. With Shadow DOM encapsulation, Angular creates the component as a real custom element in the browser, so its selector has to follow the same rules browsers apply to custom element names.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The naming rules

According to the NG2009 page, a selector used with ViewEncapsulation.ShadowDom must meet three conditions:

  • It is lowercase.
  • It contains a hyphen.
  • It begins with a letter from a to z.

A selector such as comp fails because it has no hyphen. A selector such as MyComp fails because it is not lowercase. Either one triggers NG2009 when the component uses Shadow DOM encapsulation.

How to fix NG2009

  1. Open the component file that triggers the error. Search the project for ViewEncapsulation.ShadowDom if the error message does not name the file.
  2. Find the selector property inside the @Component decorator.
  3. Rename the selector so it is lowercase, contains at least one hyphen, and starts with a letter. Keep the prefix consistent with the rest of your project, for example app-.
  4. Update every template that uses the old selector name, such as <comp>, so it matches the new name.
  5. Save the file and rebuild or restart the development server, then confirm the compiler error no longer appears.

The before-and-after from Angular’s example looks like this:

// Invalid: no hyphen
@Component({
  selector: 'comp',
  encapsulation: ViewEncapsulation.ShadowDom
})

// Valid: lowercase, hyphenated, starts with a letter
@Component({
  selector: 'app-comp',
  encapsulation: ViewEncapsulation.ShadowDom
})

The change to the selector also changes how the component is written in parent templates. If the template contains <comp>, it must become <app-comp>, or Angular will not render the component.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When the selector already looks correct

If the selector already meets all three rules and NG2009 still appears, check that you are looking at the component the compiler reports. Duplicate component files, a copied decorator in a different folder, or a stale build output can all point you at the wrong selector. The NG2009 page itself describes only the selector rule, so for any other cause, compare your code against the current Angular error reference.

Why the hyphen rule exists

Shadow DOM encapsulation in Angular relies on the browser’s custom element mechanism. Custom element names are required to contain a hyphen, and that requirement is what distinguishes them from built-in HTML tags. Angular enforces the same constraint at compile time so that the error appears during the build rather than as a silent rendering problem in the browser.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Quick checklist

  • The selector is in lowercase.
  • The selector contains a hyphen.
  • The selector starts with a letter from a to z.
  • Every template that uses the component uses the new selector.

Applying these checks resolves the error that the NG2009 page documents.

“

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.