Skip to content

How to Fix Angular Component Not Found

DodaTech Updated 2026-06-24 3 min read

In this tutorial, you'll learn about How to Fix Angular Component Not Found. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

The Problem

Angular throws Component 'AppComponent' is not included in a module or the component does not render when the custom element selector is used in a template, typically from a missing declaration or incorrect selector.

Quick Fix

Step 1: Declare the component in an NgModule

Components must be declared in exactly one module:

import { Component } from '@angular/core';

@Component({
    selector: 'app-user',
    template: '<p>User component</p>'
})
export class UserComponent { }

If UserComponent is not declared in any module, it cannot be used. Add it:

@NgModule({
    declarations: [
        UserComponent
    ]
})
export class AppModule { }

Step 2: Use the correct selector

The selector must match what is in the template:

@Component({
    selector: 'user-profile',
    template: '...'
})

Usage in template:

<user-profile></user-profile>

Not <app-user-profile> or <UserProfile>.

Step 3: Export the component for use in other modules

Components declared in a module are not visible outside it unless exported:

@NgModule({
    declarations: [UserComponent],
    exports: [UserComponent]  // Make it available to importing modules
})
export class UserModule { }

Step 4: Import the module that declares the component

The using module must import the declaring module:

@NgModule({
    imports: [UserModule],  // Now UserComponent is usable
    declarations: [AppComponent]
})
export class AppModule { }

Step 5: Check for standalone components (Angular 14+)

Standalone components do not need NgModule:

@Component({
    selector: 'app-standalone',
    template: '<p>Standalone works</p>',
    standalone: true
})
export class StandaloneComponent { }

Use directly by importing:

@Component({
    selector: 'app-root',
    standalone: true,
    imports: [StandaloneComponent],
    template: '<app-standalone />'
})
export class AppComponent { }

Prevention

  • Generate components with Angular CLI: ng generate component user.
  • Keep one component per file for clarity.
  • Use the --module flag when generating to auto-declare.
  • Use standalone components to avoid NgModule boilerplate.
  • Export reusable components from shared modules.

Common Mistakes with component not found

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world Angular code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Can I declare a component in multiple modules?

No. A component can be declared in exactly one NgModule. If you need the same component in multiple modules, extract it into a shared module and import that module wherever needed. Declaring the same component in two modules causes a compile error.

What is the difference between declarations and imports?

declarations register components, directives, and pipes that belong to the module. imports bring in other modules whose exported declarations become available. A component must be declared once and either used within the same module or exported for use by importing modules.

Why does my component render but show nothing?

The component may be missing a template or have an empty template. Check that the template or templateUrl property is set in the @Component decorator. If using templateUrl, verify the file path is correct and the file exists. An empty template renders nothing.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro