Angular Alert: The element 'app-header' is unrecognized in Angular 9

After updating my Angular application from version 5 to version 9, I encountered an error when trying to run it. The error can be seen in the following link: Error Screenshot

Below are the details of my code:

app.module.ts

import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
    
@NgModule({
  declarations: [
    AppComponent,
    HeaderComponent,
  ],

  imports: [
    BrowserModule,
    FormsModule,
    HttpClientModule,
   ],
  schemas: [ CUSTOM_ELEMENTS_SCHEMA],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {

}

app.component.ts

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
})
export class AppComponent implements OnInit {

  constructor() {
   
  }

  ngOnInit(): void {
   
  }

}

app.component.html

<app-header>

</app-header>
<script src="../../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../../node_modules/jqueryui/jquery-ui.js"></script>

<div id="circle">
  <div class="loader">
    <div class="loader">
        <div class="loader">
           
        </div>
    </div>
  </div>
</div> 

<div id="container"> 
  <div id="test1" class="test1"></div>
</div>

app.header.component.ts

import { Component, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html'
})
export class HeaderComponent implements OnInit {

  constructor(private sanitizer: DomSanitizer) {
  }

  ngOnInit() {
  
  }    
}

Note :

  1. I have not defined any extra module for headers
  2. The header component is declared in the 'declaration' section of app.module.ts file.
  3. The application was functioning properly until the upgrade to version 8. The error started occurring after migrating to version 9.

Answer №1

Following the update to the latest version of Angular,

if you wish to define components in one module and utilize them in another module, it is important to export them. This way, when you import the module into another module, it will recognize that these components are meant for external use.

In your app.module.ts, ensure to both declare and export the components so that the importing module can properly identify them as being from other modules.

app.module.ts

exports: [
  HeaderComponent,
],

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The service method call does not occur synchronously

In my OrderServer class, I am utilizing an OrderService to connect to a database and retrieve data every minute. The communication with the web app is handled through SocketIO. Here is a snippet of the code: export class OrderServer { // some required fie ...

Angular tree grid with advanced data buffering functionality

Currently, I am working with angular 7 and in need of a tree grid plugin that includes a buffering feature for loading a large quantity of records. The goal is to load only the visible part of the record initially, then progressively load additional reco ...

Using a loop variable within a callback function in JavaScript/TypeScript: Tips and tricks

I have a method in my TypeScript file that looks like this: getInitialBatches() { var i = 0; for (var dto of this.transferDTO.stockMovesDTOs) { i++; this.queryResourceService .getBatchIdUsingGET(this.batchParams) ...

Expo-three is experiencing an issue with its lights not functioning properly in threejs

Seeking assistance: I recently discovered the compatibility of the ThreeJS library with react-native, which is truly remarkable! After conducting a small experiment, I encountered some issues with the lighting. Unfortunately, I am unable to modify the ligh ...

Having difficulty testing an Angular/NGXS action that triggers after an unsuccessful API request

Struggling with writing tests for an NGXS action that calls an http request? Want to add tests for both successful and failed requests? Here is the code for my Action: @Action(SearchChuckNorrisJokes) searchChuckNorrisJokes({ getState, setState }: StateCo ...

Easily generate a component directory complete with all essential files in just a few simple clicks

In my work with React and the typical app structure, I utilize a directory called src/components to store all of my React components. I am looking for a way to streamline the process of creating new components. I would like to be able to generate a compon ...

There seems to be an issue with the reduction function in TypeScript, where an element is implicitly assigned the 'any' type due to the type of expression

I'm having an issue with the following code which represents grades of students. let students: { [k: number]: string[] } = {}; students[1] = ["Student 1", "Student 2"]; students[2] = ["Student 3", "Student 4"]; console.log(students); Object.ke ...

Transferring information between pages within Next.js 13

I am currently working on a form that is meant to generate a Card using the information inputted into the form, which will then be displayed. While I have successfully implemented the printing feature, I am having difficulty transferring the form data to t ...

How can I loop through a JSON object in Angular 8 using a function?

Within my component.ts file, I have developed a function: getData(id) { const idMod = id const idModN = document.getElementById("idMod").innerHTML = idMod console.log (idModN) } My goal is to click on a button and have the id of each ...

In TypeScript, how can we specify that a key is mandatory for an object but it can be referred to by two different names?

Essentially, I'm faced with a situation where I need to handle a style object that must contain either the maxHeight or height properties. If one of these properties is included, the other becomes unnecessary. Despite my efforts, I have been unable to ...

Angular 2 Material Design

Recently updated to angular 2 rc5 and material alpha.7-4, I encountered an issue with webpack while building. For instance, when adding MdInput in the directives of a Component, I receive this error: node_modules/webpack-core/lib/NormalModuleMixin.js:151 ...

Angular fails to establish connection due to termination before receiving a handshake response

While attempting a socket connection, an error popped up. I am following this tutorial on tutorialedge.net but using a different endpoint for implementation. socket.service.ts import { Injectable } from '@angular/core'; import * as Rx from & ...

What is the best way to establish communication between sibling components in an Angular 2+ application?

I am working with 3 components that need to communicate with one another. Initially attempted using services, but they did not resolve my issue. Seeking assistance for a solution. ...

"Troubleshooting Angular Reactive Forms: Issue with Dropdown Displaying Incorrect Selected Value

Currently, I'm in the process of constructing a Reactive form using Angular 9 which involves incorporating a dropdown. The code snippet below illustrates the dropdown component: <form [formGroup]="registerForm" (ngSubmit)="onSubmit()"> ... ...

Angular Material's Expansion Panel Alignment

I am currently facing an issue with aligning the icon to the left side of the expansion panel and centering the title. I've tried using CSS with text-align but it's not working as expected. Any advice or suggestions would be greatly appreciated, ...

Methods for incorporating type definitions into untyped npm modules when working with Typescript on a local level

Although this question has been asked and answered multiple times since 2017, I have been struggling to make it work for my project. Specifically, I have set noImplicitAny: true in my tsconfig.json, and I am trying to utilize the clamscan package which doe ...

Angular 5 ngIfElse: How to save the outcome of a condition in a storage container

Code Snippet: <mat-icon [ngClass]='{ rotate: !users }'>refresh</mat-icon> <div *ngIf="usersObservable | async as users; else loading"> ... </div> <ng-template #loading let-users> Waiting... </ng-template> ...

The type argument '(id: any, title: any, body: any, image: any) => Element' does not match the parameter type

Hello there, I am a beginner in React-Native and I'm facing an issue while trying to map data into View. Despite going through the documentation and other resources, I haven't been able to figure out what mistake I might be making. Can anyone hel ...

Angular CLI "serve" encountered a 404 status code when using CURL, yet the webpage is loading successfully in the browser

As I develop a new application using angular2 within Electron, I always aim to automate every aspect of the process. To achieve this, I have implemented various NPM scripts for serving, building, and packaging within the Electron wrapper. However, I am cur ...

The @IsEnum function does not support converting undefined or null values to objects

When I tried to use the IsEnum class validator in the code snippet below: export class UpdateEvaluationModelForReportChanges { @IsNotEmpty() @IsEnum(ReportOperationEnum) // FIRST operation: ReportOperationEnum; @IsNotEmpty() @IsEnum(Evaluatio ...