Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error when trying to load a "standalone" component from a module

I want to inject new standalone component CrashReportsComponent into my project. But I get an error when I try to connect a component from module-routing that the component type is not like NgModule
NgModule 'CrashReportsComponent' is not a subtype of 'NgModuleType'.

As planned by the developers, I can connect a standalone component instead of a module, and this should work without any changes in the module.

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { CommonLayoutComponent } from './common-layout.component';
import { FilterKind } from '../core/services/filter.service';

const routes: Routes = [
    {
        path: '',
        component: CommonLayoutComponent,
        children: [
            {
                path: 'crash-reports',
                loadChildren: () =>
                    import('../pages/crash-reports/crash-reports.component').then((m) => m.CrashReportsComponent),
            },
        ],
    },
];

@NgModule({
    imports: [RouterModule.forChild(routes)],
    exports: [RouterModule],
})
export class CommonLayoutRoutingModule {}
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';

@Component({
    selector: 'app-crash-reports',
    standalone: true,
    imports: [CommonModule],
    templateUrl: './crash-reports.component.html',
    styleUrls: ['./crash-reports.component.scss'],
})
export class CrashReportsComponent {
    constructor() {}
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You want loadComponent and not loadChildren, I believe.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading