How to use Augury Chrome Extension to check Lazy Loading in Angular 8
Introduction:
In this article i am going to explain how we check lazy loading diagrammatically in Angular application using Augury google chrome extension.
What is Augury?
Augury is the most used Developer Tool extension for debugging and profiling Angular applications inside the Google Chrome and Mozilla Firefox browsers.
Why Use Augury?
Augury helps Angular developers visualize the application through component trees, and visual debugging tools. Developers get immediate insight into their application structure, change detection and performance characteristics.
Augury is an application inspection tool for Angular that runs in the Web browser. It runs as a Chrome browser extension for the Developer Tools (DevTools) panel, aiding in analysis and debugging during development.
Installing Augury
The best way to install Augury is from the chrome web store. Select Extensions from the side panel, type "Augury" into the search field, and then press Enter.
https://chrome.google.com/webstore/category/extensions
For Windows and Linux, use Ctrl + Shift + I
For Mac OS X, use Cmd + Opt + I
Step:To Install Angular
Prerequisite
Basic knowledge of Angular
Visual Studio Code must be installed
Angular CLI must be installed
Node JS must be installed
Step 1:
Lets create a angular project using following npm command
- ng new AuguryDemo
First open this project in VS Code and install bootstrap by using the following command:
- npm install bootstrap --save
Now open styles.css file and add Bootstrap file reference. To add a reference in styles.css file, add this line:
- @import '~bootstrap/dist/css/bootstrap.min.css';
Now create two modules named
1.Companies
- ng g m Companies --routing
- ng g m product --routing
Now create some demo components in both of these modules by using given commands
For Companies
- ng g c company1
- ng g c company2
Now open companies-routing.module.ts file and add the following code inside this file
- import { NgModule } from '@angular/core';
- import { Routes, RouterModule } from '@angular/router';
- import { Compnay1Component } from './compnay1/compnay1.component';
- import { Compnay2Component } from './compnay2/compnay2.component';
- import { CompnayComponent } from './compnay.component';
- const routes: Routes = [
- {
- path:'Compnay1',component:Compnay1Component
- },
- {
- path:'Compnay2',component:Compnay2Component
- },
- {
- path:'Compnay',component:CompnayComponent
- }
- ];
- @NgModule({
- imports: [RouterModule.forChild(routes)],
- exports: [RouterModule]
- })
- export class CompaniesRoutingModule { }
Now create some demo components in both this modules by using given commands
For Product
- ng g c product1
- ng g c product2
Now open Product-routing.module.ts file and add the following code inside this file
- import { NgModule } from '@angular/core';
- import { Routes, RouterModule } from '@angular/router';
- import { Product1Component } from './product1/product1.component';
- import { Product2Component } from './product2/product2.component';
- import { ProductComponent } from './product.component';
- const routes: Routes = [
- {path:'Product1',component:Product1Component},
- {path:'Product2',component:Product2Component},
- {path:'prod',component:ProductComponent},
- ];
- @NgModule({
- imports: [RouterModule.forChild(routes)],
- exports: [RouterModule]
- })
- export class ProductRoutingModule { }
Now add a new component 'Home' and open home.component.html file and add following code in this file
- <div class="container">
- <button style="margin: 10px;" class="btn btn-info" (click)="product()" >Product</button>
- <button style="margin: 10px;" class="btn btn-info" (click)="company()">Company</button>
- </div>
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- @Component({
- selector: 'app-home',
- templateUrl: './home.component.html',
- styleUrls: ['./home.component.css']
- })
- export class HomeComponent implements OnInit {
- constructor(private router:Router) { }
- ngOnInit() {
- }
- product()
- {
- this.router.navigate([`/product/prod`]);
- }
- company()
- {
- this.router.navigate([`/company/Compnay`]);
- }
- }
- import { NgModule } from '@angular/core';
- import { Routes, RouterModule } from '@angular/router';
- const routes: Routes = [
- {
- path: 'product',
- loadChildren: './product/product.module#ProductModule'
- },
- {
- path: 'company',
- loadChildren: './companies/companies.module#CompaniesModule'
- },
- ];
- @NgModule({
- imports: [RouterModule.forRoot(routes)],
- exports: [RouterModule]
- })
- export class AppRoutingModule { }
- import { BrowserModule } from '@angular/platform-browser';
- import { NgModule } from '@angular/core';
- import { AppRoutingModule } from './app-routing.module';
- import { AppComponent } from './app.component';
- import { HomeComponent } from './home/home.component';
- @NgModule({
- declarations: [
- AppComponent,
- HomeComponent
- ],
- imports: [
- BrowserModule,
- AppRoutingModule
- ],
- providers: [],
- bootstrap: [AppComponent]
- })
- export class AppModule { }
- <app-home></app-home>
- <router-outlet></router-outlet>
After completion of code run the project by using "ng serve" command in VS Code
Then run this project and open in Google chrome browser and test lazy loading.
Then click on Ctrl+F12 to enable debugger and click augury tab.
Click on to Router tree here it will show the route flow of our modules .If lazy loading is applied in components the it will show in square brackets
that ,that particular component is loaded lazy or not.
The Router Tree tab is located next to the Component Tree tab along the top left side.
Now click on their child components to load there child route after clicking on all child components then this will show like below image
The first view that is visible is the Component Tree which shows loaded components belonging to the application.
The component tree displays a hierarchical relationship of the components. When a component is selected, Augury presents additional information about the selected component in the Properties tab The final major feature of Augury is the Router Tree, which displays the routing information for the application.
Comments
Post a Comment