Full answer
Since Angular 14, errors have a stable code and a link: NG0300, with https://angular.dev/errors/NG0300. The page explains the cause and fixes. Search the code, not the long message, because messages change between versions. Ranges help: NG0xxx are run time errors, and NG8xxx are template compiler errors (for example NG8001 unknown element).
NG0300: Multiple components match node with tagname 'app-dup'. An element in a template matched the selectors of two or more components (only one component can own an element). Causes:
- Two components with the same selector, both imported in the same parent (a copy and paste mistake, or a library that uses the same selector as yours).
- A very general selector such as
divor[title]on a component, which matches elements by accident.
Fixes: give each component a unique prefix (app-, school-), check the imports of the component, and make selectors specific. Use the editor's "go to definition" on the tag to see which one matched.
NG0950: Input is required but no value is available yet. A required signal input (input.required<T>()) was read before Angular set it. Inputs are set after the constructor runs, so reading this.id() in the constructor, in a field initialiser, or in a computed that is read too early fails. The compiler reports a direct read in a constructor as NG8118. Fixes: read the input in ngOnInit, in a computed that is read from the template, or in an effect. If a default is acceptable, make the input optional with input(0).
Related codes worth knowing: NG0100 (changed after checked), NG0200 (circular dependency), NG0201 (no provider), NG0203 (outside injection context), NG0912 (component ID collision, a warning), NG0913 (image much larger than it is shown), NG0500 to NG0505 (hydration problems).
Debug routine: copy the code, open the docs page, read the stack to find the first line of your own code, and reproduce in the smallest example. Keep the Angular version in mind, because new versions add and rename codes.
import { Component, input } from '@angular/core';
@Component({ selector: 'app-dup', template: `a` })
export class AComponent {}
@Component({ selector: 'app-dup', template: `b` })
export class BComponent {}
@Component({
selector: 'app-dup-host',
imports: [AComponent, BComponent], // both match <app-dup />: NG0300
template: `<app-dup />`,
})
export class DupHostComponent {}
@Component({ selector: 'app-id-view', template: `Id: {{ id() }}` })
export class IdViewComponent {
readonly id = input.required<number>();
readSoon(): number {
return this.id(); // NG0950 when called before the parent sets the input
}
}Angular 20.3. A Karma test reproduces NG0300 with two components that share a selector, and NG0950 by reading a required input before it is set. The exact message starts are checked. Both bad components compile without a compiler error in AOT here, so the errors appear at run time.
Key points
- Error codes (NG0xxx runtime, NG8xxx template compiler) link to pages with causes and fixes.
- NG0300: more than one component matches an element, often a duplicate or too general selector.
- NG0950: a required input was read before it was set. Read it in `ngOnInit`, a template-read `computed` or an `effect`.
- Search by code, and read your own first stack line.
Common mistakes
- Searching the whole message text instead of the code.
- Reusing a selector in two components that are imported together.
- Reading a required input in the constructor.
Follow-ups
- What kind of errors are the NG8xxx codes?
- How would you avoid selector clashes in a shared library?
- How can an `effect` read a required input safely?
Tips
- Show that you use the docs page for each code.
- Explain the cause of both codes in one sentence each.
- Offer a repeatable debugging routine.
Evaluation rubric
- Understands error code families and docs.
- Explains NG0300 and NG0950 causes and fixes.
- Describes a debugging method.