Lazy Load Images Angular 17

Lazy Load Images Angular 17

To lazy load images in Angular; To delay loading your images on Angular applications, simply run npm i ng-lazyload-image to install lazy load module, and then use its function [lazyLoad]=”image1″ with an image on an HTML template to defer loading images on applications.

Lazy loading of images in web pages and applications is a technique, with the help of this the speed and performance of your application becomes much faster, and at the same time it remains delayed until they are not needed in the angular application.

Angular Lazy Load Images

Steps to lazy load images in angular 17 applications:

Step 1 – Create a New Angular App

Run the ng new my-new-app command on cmd or terminal to install and create a new Angular project:

ng new my-new-app --no-standalone

Step 2 – Install Lazy Load Module

Simply run npm i ng-lazyload-image command on cmd to install lazy load image module into your angular application, it will help you to defer the loading of images until they are needed and it can improve performance: 

cd my-new-app
npm i ng-lazyload-image 

Step 3 – Import Lazy Load Image Modules

Navigate to src/app folder and open app.module.ts typescript file and import it like following into it:

import { LazyLoadImageModule} from 'ng-lazyload-image';

  declarations: [...],
  imports: [
  bootstrap: [...]

export class AppModule { }

Step 4 – Use Lazy Load Images in HTML Template

To lazy load images in html template, simply navigate to src/app/ and open app.component.html, and then use lazyload with your images like following in it:

<h1>Angular Lazy Load Image Example</h1>
   <img height="600" width="600" [lazyLoad]="image1">
  <img height="600" width="600" [lazyLoad]="image2">
  <img height="600" width="600" [lazyLoad]="image3">
  <img height="600" width="600" [lazyLoad]="image4">

   <h2>Responsive Images</h2>
   <img [defaultImage]="defaultImage" [useSrcset]="true" [lazyLoad]="images">


Step 5 – Set Images for Lazy Loading

To set images for lazy loading; Simply navigate to src/app directory and open app.component.ts, then set it like following in it:

import { Component } from '@angular/core';

  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
export class AppComponent {
  title = 'my-new-app';


    defaultImage = '';

    images = ` 700w,

Step 6 – Test the lazy loading

Run ng serve command on cmd to start the angular app:

ng serve

Visit http://localhost:4200 in your browser and check the Network tab in your browser’s developer tools. You should notice that the images are being loaded as they appear in the viewport, and not all images are loaded immediately on page load.


That’s it; you have successfully implemented and used lazy loading images in angular application.

Recommended Angular Tutorials


Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *