Reputation: 255
I have an app.module
where it imports LazyLoaderModule
.
my lazy loader module is as follows.
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Routes,RouterModule } from '@angular/router';
const routes: Routes = [
{path: 'auth', loadChildren: '../auth/auth.module#AuthModule'},
{path: 'login', loadChildren: '../login/login.module#LoginModule'},
{path: '*', redirectTo: 'login'},
]
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class LazyLoadModule { }
In my lazyloader router I have the routes as follows
import { RouterModule, Routes } from '@angular/router';
import { AuthComponent } from '../../Components/auth/auth.component';
export const appRoutes: Routes = [{
path: '', component: AuthComponent, children: [
{ path: 'orders', loadChildren: '../orders/orders.module#OrdersModule' },
{ path: 'tables', loadChildren: '../../tables/tables.module#TablesModule' },
{ path: 'guarded-routes', loadChildren: '../../guarded-routes/guarded-routes.module#GuardedRoutesModule' },
{ path: 'maps', loadChildren: '../../maps/maps.module#MapsModule' },
]
}];
I want to import a new Module
import { MomentModule } from 'ngx-moment';
in the AppModule
to be imported in the OrdersModule
however, when I import in the app module I get an error.
BUT when I import in the orders module it works.
my goal is to use the MomentModule in the whole app and not just the ordersModule.
Upvotes: 1
Views: 522
Reputation: 222582
Best way to handle this would be, import the MomentModule in a SharedModule and export it.
Something like,
import {MomentModule} from 'ngx-moment';
@NgModule({
imports: [
MomentModule
],
exports: [
MomentModule
]
})
and use it in the app.module as
SharedModule.forRoot()
Upvotes: 2