[英]AngularCli Import node module to angular app.module loadChildren
I want to import my module from node modules. 我想从节点模块导入我的模块。 This node module has routes that I need to navigate too.
该节点模块也具有我也需要导航的路由。
The outcome I need: 我需要的结果:
Wire up my app.module to have loadChildren from the module in my node modules. 连接我的app.module, 使其节点模块中的模块具有loadChildren 。 TestModule needs wiring up to forRoot so I can lazy load TestModules routes.
TestModule需要连接到forRoot,因此我可以延迟加载TestModules路由。
TestModule is a dist folder thats been added to node modules using angular cli version 6 built in ng-packagr. TestModule是一个dist文件夹,已使用ng-packagr中内置的angular cli版本6添加到节点模块。
This is my core app module: 这是我的核心应用程序模块:
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 { }
This is the imported TestModule (that is an npm package): 这是导入的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 {}
This is my core app tsconfig.aoo.json: 这是我的核心应用程序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"
]
}
Info: 信息:
When I do an ng serve to port localhost:4200 I get no console errors and no git command errors. 当我对端口localhost:4200执行ng服务时,没有控制台错误和git命令错误。
I'm using angular cli 6 with angular 6, ng-packagr, webpack and iterm for git cli. 我正在将angular cli 6与angular 6,ng-packagr,webpack和iterm用于git cli。
Its hard to debug as I have no errors to work with. 调试起来很困难,因为我没有遇到任何错误。 It seems like the core app module isn't loading though.
核心应用模块似乎没有加载。
AFAIK,当您延迟加载模块时,一定不要同时导入它。尝试从app.module.ts中的导入中删除TestModule。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.