[英]AngularCli Import node module to angular app.module loadChildren
我想从节点模块导入我的模块。 该节点模块也具有我也需要导航的路由。
我需要的结果:
连接我的app.module, 使其节点模块中的模块具有loadChildren 。 TestModule需要连接到forRoot,因此我可以延迟加载TestModules路由。
TestModule是一个dist文件夹,已使用ng-packagr中内置的angular cli版本6添加到节点模块。
这是我的核心应用程序模块:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { TestModule } from "test";
@NgModule({
declarations: [
AppComponent
],
imports: [
TestModule,
BrowserModule,
RouterModule.forRoot(
[
{
path: "",
redirectTo: "test",
pathMatch: "full"
},
{
path: "test",
loadChildren: "test#TestModule"
},
])
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
这是导入的TestModule(这是一个npm包):
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { HomeComponent } from './containers/home/home.component';
import { LayoutSidebarComponent } from './layouts/layout-sidebar/layout-sidebar.component';
const COMPONENTS = [
HomeComponent
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild([
{
path: '',
pathMatch: 'full',
component: LayoutSidebarComponent,
children: [
{
path: '',
component: HomeComponent
}
]
}
])
],
declarations: [...COMPONENTS],
exports: []
})
export class TestModule {}
这是我的核心应用程序tsconfig.aoo.json:
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "../out-tsc/app",
"module": "es2015",
"types": [
"node"
]
},
"include": [
"../node_modules/test/**/*.ts"
],
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}
信息:
当我对端口localhost:4200执行ng服务时,没有控制台错误和git命令错误。
我正在将angular cli 6与angular 6,ng-packagr,webpack和iterm用于git cli。
调试起来很困难,因为我没有遇到任何错误。 核心应用模块似乎没有加载。
AFAIK,当您延迟加载模块时,一定不要同时导入它。尝试从app.module.ts中的导入中删除TestModule。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.