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. TestModule needs wiring up to forRoot so I can lazy load TestModules routes.
TestModule is a dist folder thats been added to node modules using angular cli version 6 built in ng-packagr.
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):
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:
{
"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.
I'm using angular cli 6 with angular 6, ng-packagr, webpack and iterm for 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。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.