I'm having a problem that i can't understand.
Basically, i have the app module (app.module.ts) with a async route (app-routing.module.ts) to other module (design-system.module.ts). A component (design-system.component.ts) of this async module calls a component of a third module (ButtonModule). The component of main module gives no problem (AppComponent) when calling the third module, but the async module gives an error (DesignSystemModule).
Files
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, AppRoutingModule],
bootstrap: [AppComponent],
})
export class AppModule {}
app-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{
path: 'design-system',
loadChildren: () =>
import('./design-system/design-system-routing.module').then(
(m) => m.DesignSystemRoutingModule
),
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
design-system.module.ts
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { ButtonModule } from '../components/button/button.module';
import { DesignSystemRoutingModule } from './design-system-routing.module';
import { DesignSystemComponent } from './design-system.component';
@NgModule({
declarations: [DesignSystemComponent],
imports: [CommonModule, DesignSystemRoutingModule, ButtonModule],
})
export class DesignSystemModule {}
design-system-routing.module.ts
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { DesignSystemComponent } from './design-system.component';
const routes: Routes = [{ path: '', component: DesignSystemComponent }];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class DesignSystemRoutingModule {}
design-system.component.html
<app-button></app-button>
<p style="color: white;">design-system works!</p>
button.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ButtonComponent } from './button.component';
@NgModule({
declarations: [ButtonComponent],
imports: [CommonModule],
exports: [ButtonComponent],
})
export class ButtonModule {}
The error
error NG8001: 'app-button' is not a known element:
1. If 'app-button' is an Angular component, then verify that it is part of this module.
2. If 'app-button' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
Angular CLI: 12.2.1
Node: 14.17.0
Package Manager: npm 6.14.13
OS: win32 x64
Angular: 12.2.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1202.1
@angular-devkit/build-angular 12.2.1
@angular-devkit/core 12.2.1
@angular-devkit/schematics 12.2.1
@schematics/angular 12.2.1
rxjs 6.6.7
typescript 4.3.5