在Angular4中实现懒加载html、js、css等资源。利用Angular CLI实现懒加载,通过loadChildren以两种方式加载module。
Angular CLI版本为 1.1.0.
about文件夹下是通过在router中以loadChildren: ' ../about/about.module#AboutModule'的方式。
contact文件夹下是:定义contact的module并导出module,在routing中首先定义函数:export function loadBundledModule() { return ContactModule; } 在router中引用component: HelloComponent,实现加载module。
文件目录结构
git项目地址:angular4-lazyload。
注意:需要童鞋们对Angular4有一定的了解。