Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while implenting lazy-loading in angular 8: : ASSERTION ERROR: NgModule 'MyReportsGridComponent' is not a subtype of 'NgModuleType'

I read some articles can't seem to implement lazy-loading my application. I have angular 8 installed and it seems I have the right syntax. Is there a specific strategy or way I need to have my components organized to get lazy loading to work?

This is the error message:

core.js:7187 ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: NgModule 'MyReportsGridComponent' is not a subtype of 'NgModuleType'.
Error: ASSERTION ERROR: NgModule 'MyReportsGridComponent' is not a subtype of 'NgModuleType'.

in my app.routing.module.ts where is what I have:

const routes: Routes = [
  {path: '', component:LoginComponent},
  {path: 'Login', component:LoginComponent},
  {path: 'tasks', component:TaskComponent, canActivate:[AuthGuard]},
  {path: 'CreateTask', loadChildren: () => import ('./create-task/create-task.component').then(m => m.CreateTaskComponent), canActivate:[AuthGuard]},
  {path: 'ManageUser', loadChildren: () => import ('./manage-users/manage-users.component').then(m => m.ManageUsersComponent), canActivate:[AuthGuard]},
  {path: 'MyReports', loadChildren: () => import ('./my-reports-grid/my-reports-grid.component').then(m => m.MyReportsGridComponent), canActivate:[AuthGuard]},
  {path: 'CreateTeamName',loadChildren: () => import ('./create-new-team-name/create-new-team-name.component').then(m => m.CreateNewTeamNameComponent), canActivate:[AuthGuard]},
  {path: 'ManageTeams',loadChildren: () => import ('./manage-teams/manage-teams.component').then(m => m.ManageTeamsComponent), canActivate:[AuthGuard]},
  { path: '**', component: PageNotFoundComponent },
  {path: 'Register', component:RegisterComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes, { useHash: true, enableTracing: false, initialNavigation: true, onSameUrlNavigation: 'ignore' })],
  exports: [RouterModule]
})
export class AppRoutingModule { }

Any suggestions?

like image 979
elquesogrand Avatar asked Jul 28 '19 19:07

elquesogrand


3 Answers

Just stumbled across this as well. Looks like you are trying to lazy load Components instead of Modules. Check here: https://angular.io/guide/ngmodules

like image 198
beluga Avatar answered Nov 18 '22 18:11

beluga


You try this one and let me know its working or not I will update you

GridModuleName its your module class name

{
path: 'myreports',
loadChildren: './my-reports-grid/my-reports-grid.component#GridModuleName',
data: {
  pageTitle: 'MyReports'
 }
}
like image 40
Mokka soru Avatar answered Nov 18 '22 18:11

Mokka soru


I got exactly this error when I set the bootstrap as AppModule instead to set AppComponent.

That happened to me because I was doing a few tests. Bad mistake.

like image 1
AFetter Avatar answered Nov 18 '22 18:11

AFetter