I use angular 9 and I want to do lazy load and I do app-routing
{
path: '', loadChildren: () => import("./components/login/login.module")//.then(m =>
// m.LoginModule)
}
and after I create login module:
@NgModule({
declarations: [LoginComponent],
imports: [
CommonModule,
FormsModule,
LoginModuleRouting
],
providers:[]
})
export class LoginModule { }
and routing:
const routes: Routes = [
{
path: '', component: LoginComponent,
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class LoginModuleRouting { }
the proble is that when I call ng serve
and I go on `http://localhost:4200/, I obtain this exception:
core.js:6237
ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: NgModule '[object Module]' is not a subtype of 'NgModuleType'. [Expected=> null != null <=Actual]
Error: ASSERTION ERROR: NgModule '[object Module]' is not a subtype of 'NgModuleType'. [Expected=> null != null <=Actual]
I don't knwo what it means. Anyone can help me?
I don't know why but you have commented out your login module on loadChildren() here:
{
path: '',
loadChildren: () => import("./components/login/login.module")//.then(m =>
// m.LoginModule)
}
and it should be:
{
path: '',
loadChildren: () => import("./components/login/login.module").then(m => m.LoginModule)
}
I also had this issue.
My problem was that I declared the NgModule without @. Adding it fixed the message.
I know that the original cause of this was because of promise resolution being commented out, but I wanted to add another cause since this is the highest hit on Google for this error and there are multiple causes.
This can also be caused if you're trying to use a component as a module. Using component: MyComponentName
instead of loadChildren: () => import('./my-component.component').then( m => m.MyComponent)
will resolve this issue too. If you intended it to be a module, you can use ng generate module
to create a module instead if you want to delegate routing to another module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With