Angular 2 Lazy用角度路由器在NPM模块中加载NgModule [英] Angular 2 Lazy loading a NgModule in a NPM module with angular router

查看:82
本文介绍了Angular 2 Lazy用角度路由器在NPM模块中加载NgModule的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在例如路线中懒加载模块

I have been lazy loading modules in routes e.g.

export const HomeRoute: Route = {
  path: '',
  component: HomeComponent,
  canActivate: [AuthGuard],
  children: [
    {path: 'dashboard', loadChildren: 'app/+dashboard/db.module#DashboardModule'}
  ]
};

我想将我的页面"放入NPM模块中.在loadChildren属性中应使用的到node_module的路由是什么?我正在使用angular-cli 1.0.0-beta.16

I would like to put my "pages" into NPM modules. What is the route to the node_module that I should use in the loadChildren attribute? I am using angular-cli 1.0.0-beta.16

我尝试过

{path: 'lazy', loadChildren: '../node_modules/hello-world/components#HelloWorld' }

{path: 'lazy', loadChildren: 'hello-world/components#HelloWorld' }

导出的类为:-

import {Component} from '@angular/core';

@Component({
    selector: 'hello-world',
    styles: [`
       h1 {
            color: blue;
        }
    `],
    template: `<div>
                  <h1 (click)="onClick()">{{message}}</h1>
               </div>`
})
export class HelloWorld {

    message = "Click Me ...";

    onClick() {
        this.message = "Hello World!";
        console.log(this.message);

    }
}

还有什么我应该尝试的吗?

Is there anything else I should try?

推荐答案

目前无法实现-在此处查看AngularJS CLI团队的回复:-

This currently isn't possible - see a response from the AngularJS CLI team here: -

https://github.com/angular/angular-cli/issues/2601

这是一个非常相关的问题.我不认为我们会在 CLI atm."(当前为beta 17版)

"This is a very relevant question. I don't think we support it in the CLI atm." (Currently version beta 17)

Datumgeek在此处(CLI之外)以不同的方式从模块实现了延迟加载:-

Datumgeek has implemented lazy loading from modules in a different way (outside of CLI) here: - https://github.com/datumgeek/a2dyn/blob/master/README.md#development-server

如果将来在Angular CLI中有可能,我将更新答案

I will update the answer if it becomes possible in the Angular CLI in the future

这篇关于Angular 2 Lazy用角度路由器在NPM模块中加载NgModule的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆