app.module
インポートする場所がありLazyLoaderModule
ます。
私のレイジーローダーモジュールは次のとおりです。
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 { }
私のレイジーローダールーターには、次のようなルートがあります
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' },
]
}];
新しいモジュールをインポートしたい
import { MomentModule } from 'ngx-moment';
にAppModule
インポートされますthe OrdersModule
ただし、appモジュールにインポートすると、エラーが発生します。
しかし、ordersモジュールにインポートすると機能します。
私の目標は、ordersModuleだけでなく、アプリ全体でMomentModuleを使用することです。
これを処理する最良の方法は、MomentModuleをSharedModuleにインポートしてエクスポートすることです。
何かのようなもの、
import {MomentModule} from 'ngx-moment';
@NgModule({
imports: [
MomentModule
],
exports: [
MomentModule
]
})
app.moduleで次のように使用します
SharedModule.forRoot()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加