Ash*_*ell 7 angular2-routing angular-cli angular
我一直懒得在路线上加载模块,例如
export const HomeRoute: Route = {
path: '',
component: HomeComponent,
canActivate: [AuthGuard],
children: [
{path: 'dashboard', loadChildren: 'app/+dashboard/db.module#DashboardModule'}
]
};
Run Code Online (Sandbox Code Playgroud)
我想将我的"页面"放入NPM模块中.我应该在loadChildren属性中使用node_module的路由是什么?我使用的是angular-cli 1.0.0-beta.16
我试过了
{path: 'lazy', loadChildren: '../node_modules/hello-world/components#HelloWorld' }
Run Code Online (Sandbox Code Playgroud)
也
{path: 'lazy', loadChildren: 'hello-world/components#HelloWorld' }
Run Code Online (Sandbox Code Playgroud)
导出的类是: -
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);
}
}
Run Code Online (Sandbox Code Playgroud)
还有什么我应该尝试的吗?
目前这是不可能的 - 请参阅此处 AngularJS CLI 团队的回复:-
https://github.com/angular/angular-cli/issues/2601
“这是一个非常相关的问题。我认为我们在 CLI atm 中不支持它。” (当前版本为 beta 17)
Datumgeek 在这里以不同的方式(在 CLI 之外)实现了模块的延迟加载: - https://github.com/datumgeek/a2dyn/blob/master/README.md#development-server
如果将来在 Angular CLI 中可行的话我会更新答案
| 归档时间: |
|
| 查看次数: |
1195 次 |
| 最近记录: |