在Angular4中實(shí)現(xiàn)懶加載html、js、css等資源。利用Angular CLI實(shí)現(xiàn)懶加載,通過loadChildren以兩種方式加載module。
Angular CLI版本為 1.1.0.
about文件夾下是通過在router中以loadChildren: ' ../about/about.module#AboutModule'的方式。
contact文件夾下是:定義contact的module并導(dǎo)出module,在routing中首先定義函數(shù):export function loadBundledModule() { return ContactModule; } 在router中引用component: HelloComponent,實(shí)現(xiàn)加載module。
文件目錄結(jié)構(gòu)

git項(xiàng)目地址:angular4-lazyload。
注意:需要童鞋們對Angular4有一定的了解。