I'm want to implement Angular lazing loading in my app.
I read through so many books and it seems this the normal way to do it, maybe I missed something important and it's been two days.
https://github.com/kondasMajid/angula-lazy-loading
App-routing-Module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{
path: '',
redirectTo: '',
pathMatch: 'full'
},
{
path: 'home',
loadChildren: './home/home.module#HomeModule'
},
{
path: 'view',
loadChildren: 'app/view/view.module#ViewModule'
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
app.component.html
<button routerLink="/view">view</button>
<router-outlet></router-outlet>
view.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ViewRoutingModule } from './view-routing.module';
import { RouterModule, Routes } from '@angular/router';
import { ViewComponent } from './view.component';
const routes: Routes = [
{
path: '',
component: ViewComponent
}
];
@NgModule({
declarations: [],
imports: [
CommonModule,
ViewRoutingModule,
RouterModule.forChild(routes)
]
})
export class ViewModule { }
view.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'view',
templateUrl: './view.component.html',
styleUrls: ['./view.component.css']
})
export class ViewComponent implements OnInit {
constructor() {}
ngOnInit() {}
}
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'view', templateUrl: './view.component.html', styleUrls: ['./view.component.css'] }) export class ViewComponent implements OnInit { constructor() { } ngOnInit() { } }