Home Angular 8 How to Implement Owl Carousel Slider in Angular 8?

How to Implement Owl Carousel Slider in Angular 8?

by therichpost
Published: Updated: 19 comments
Angular 8 owl carousel with Laravel 6 backend images

Hello to all, welcome to therichpost.com. Today In this post, I will tell you, How to Implement Owl Carousel Slider in Angular 8?

I am very happy during sharing this post. I faced some error but no one will face any error with my code.

Slider are the main part of lading page and today we will implement Owl carousel Slider in Angular 8.

Here is the working picture:

How to Implement Owl Carousel Slider in Angular 7

Here is the complete working and tested code, you need to follow:

1. Very first, here are common basics steps to add angular 8 application on your machine:

$ npm install -g @angular/cli

$ ng new angularowlslider // Set Angular8 Application on your pc

cd angularowlslider // Go inside project folder

ng serve // Run project

http://localhost:4200/  //Check working Local server

2. Now run below command into your terminal to include owl carousel package into your angular 8 application:

npm i ngx-owl-carousel-o

3. Now, add below code into your angular.json file:

....
"styles": [
    "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.carousel.min.css",
    "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.theme.default.min.css",
    "src/styles.css"
  ],
....

4. Now add below code into your app.module.ts file:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { CarouselModule } from 'ngx-owl-carousel-o';
import { AppComponent } from './app.component';
import { Routes, RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CarouselModule,
    BrowserAnimationsModule,
     RouterModule.forRoot([]),
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

5. Now add below code into your app.component.ts file:

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'angularowlslider';
  customOptions: any = {
    loop: true,
    mouseDrag: false,
    touchDrag: false,
    pullDrag: false,
    dots: false,
    navSpeed: 700,
    navText: ['', ''],
    responsive: {
      0: {
        items: 1
      },
      400: {
        items: 2
      },
      740: {
        items: 3
      },
      940: {
        items: 4
      }
    },
    nav: true
  }
}

6. Finally add, below code into your app.component.html file:

<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
  <div>Some tags before</div>
    <owl-carousel-o [options]="customOptions">
    <ng-template carouselSlide><img src="https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg"></ng-template>  
    <ng-template carouselSlide><img src="https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg"></ng-template>  
    <ng-template carouselSlide><img src="https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg"></ng-template> 
    <ng-template carouselSlide><img src="https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg"></ng-template>  
    <ng-template carouselSlide><img src="https://jaxenter.de/wp-content/uploads/2016/01/angularjs_2_0-log-500x375.jpg"></ng-template>  
  </owl-carousel-o>
  <div>Some tags after</div>
</div>

This is it and don’t forget run ng serve command again. Please follow the code and you will not face any kind of error.

If you have any query related to this post then please do comment below or ask question.

Thank you,

Jas

TheRichPost

You may also like

19 comments

Akash December 21, 2019 - 6:41 pm

how to make it dynamic

Reply
Ajay Malhotra December 22, 2019 - 3:46 am

Hi Akash, you can make dynamic with Httpclient API requests.

Reply
Vikas February 21, 2020 - 11:29 am

how can i provide space between images?

Reply
Ajay Malhotra February 21, 2020 - 1:38 pm

you can do with css..

Reply
Akhil Jain March 30, 2020 - 12:30 pm

getting error error TS1086: An accessor cannot be declared in an ambient context. in qwl carousel

Reply
Ajay Malhotra March 30, 2020 - 3:37 pm

are you using this in Angular 9?

Reply
Nilesh Sutar April 10, 2020 - 4:38 am

Add “skipLibCheck”: true in tsconfig.json file to resolve it.

Reply
Ajay Malhotra April 10, 2020 - 4:40 am

good

Reply
Sai Aung Mein April 11, 2020 - 8:18 am

node_modules/ngx-owl-carousel-o/lib/services/document-ref.service.d.ts:10:9 – error TS1086: An accessor cannot be declared in an ambient context.

Reply
Ajay Malhotra April 11, 2020 - 4:09 pm

Let me update you.

Reply
Abbaty Abdul May 6, 2020 - 10:00 am

Thanks you very much, this very helpful, works 100%, please did you have any best way to send a mail message from my angular 9 app

Reply
Ajay Malhotra May 6, 2020 - 10:03 am

Hi, yes I have tutorial angular with laravel. angular with node. you can find via my blog search.

Thanks

Reply
marcello May 12, 2020 - 12:23 pm

node_modules/ngx-owl-carousel-o/lib/services/document-ref.service.d.ts:10:9 – error TS1086: An accessor cannot be declared in an ambient context.

Reply
Ajay Malhotra May 12, 2020 - 12:26 pm

I think, you need to install latest:
ng update @angular/core @angular/cli

Reply
guru prasad October 9, 2020 - 10:08 am

How can we make scrollable buttons into 4 you have shown only two(prev and next )but how can we make into 4

Reply
mehdi October 25, 2020 - 11:10 pm

hi
thank you for your useful component, but how can I increase number of item in same page?
for example I want to add 8 picture in same page but i can’t find this option, in your component.

Reply
Ajay Malhotra October 26, 2020 - 5:28 am

You can and this is simple and here are the options:
responsive: {
0: {
items: 1
},
400: {
items: 2
},
740: {
items: 3
},
940: {
items: 4
}
}

Reply
mehdi October 28, 2020 - 7:59 pm

hi and thank you for your response
it doesn’t work and still appeal to me with 3 picture.
I change the items to 6 but it doesn’t work
how can I solve this??

Reply
neha September 4, 2022 - 12:05 pm

i need to insert a link along with image by http of api url

Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.