Angular 16 Slick Carousel Slider Integration Example

Angular 16 slick carousel example; Through this tutorial, i am going to show you how to implement and use slick carousel in Angular 16 apps using ngx-slick-carousel-o library.

Angular 16 Slick Carousel Slider Integration Example

Follow the below given steps to implement carousel slider using slick plugin in Angular 16 apps; as follows:

  • Step 1 – Create New Angular App
  • Step 2 – Install slick Carousel Library
  • Step 3 – Import Modules in Module.ts File
  • Step 4 – Create Carousel Slider in View File
  • Step 5 – Import Components in Component ts File
  • Step 6 – Start the Angular App

Step 1 – Create New Angular App

Run the following command on command prompt to install angular app:

ng new my-new-app

Step 2 – Install slick Carousel Library

Run the following commands on command prompt to install NPM package called ngx-slick-carousel –save for implement slick carousel in angular apps:

npm install jquery --save
npm install slick-carousel --save
npm install ngx-slick-carousel --save

After that, open angular.json file and update the following code into it:

...
"styles": [
  "node_modules/slick-carousel/slick/slick.scss",
  "node_modules/slick-carousel/slick/slick-theme.scss"
],
"scripts": [
  "node_modules/jquery/dist/jquery.min.js",
  "node_modules/slick-carousel/slick/slick.min.js"
]
....

Step 3 – Import Modules in Module.ts File

Go to src/app directory and open app.module.ts file. And then add the following lines of into app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
  
import { AppComponent } from './app.component';
import { SlickCarouselModule } from 'ngx-slick-carousel';
  
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SlickCarouselModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Step 4 – Create Carousel Slider in View File

Go to src/app/ and app.component.html and update the following code into it:

<h1>Angular Slick Carousel Slider Integration Tutorial - Laratutorials.com</h1>
  
<ngx-slick-carousel class="carousel" 
                        #slickModal="slick-carousel" 
                        [config]="slideConfig" 
                        (init)="slickInit($event)"
                        (breakpoint)="breakpoint($event)"
                        (afterChange)="afterChange($event)"
                        (beforeChange)="beforeChange($event)">
        <div ngxSlickItem *ngFor="let slide of slides" class="slide">
              <img src="{{ slide.img }}" alt="" width="100%">
        </div>
</ngx-slick-carousel>

Step 5 – Import Components in Component ts File

Go to the src/app directory and open app.component.ts. Then add the following code into component.ts file:

import { Component } from '@angular/core';
  
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'ng-carousel-demo';
  
  slides = [
    {img: "https://dummyimage.com/350x150/423b42/fff"},
    {img: "https://dummyimage.com/350x150/2a2b7a/fff"},
    {img: "https://dummyimage.com/350x150/1a2b7a/fff"},
    {img: "https://dummyimage.com/350x150/7a2b7a/fff"},
    {img: "https://dummyimage.com/350x150/9a2b7a/fff"},
    {img: "https://dummyimage.com/350x150/5a2b7a/fff"},
    {img: "https://dummyimage.com/350x150/4a2b7a/fff"}
  ];
  slideConfig = {"slidesToShow": 4, "slidesToScroll": 4};
  
  slickInit(e) {
    console.log('slick initialized');
  }
    
  breakpoint(e) {
    console.log('breakpoint');
  }
    
  afterChange(e) {
    console.log('afterChange');
  }
    
  beforeChange(e) {
    console.log('beforeChange');
  }
}

Step 6 – Start the Angular App

Run the following command on command prompt to start angular slick carousel app:

ng serve

Recommended Angular Tutorials

Leave a Comment