簡體   English   中英

AngularCli將節點模塊導入到角度app.module loadChildren

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM