Home Angular 8 Angular 9 Material Carousel Slider

Angular 9 Material Carousel Slider

by therichpost
Published: Updated: 75 comments
Angular 9 Material Carousel Slider

Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 9 Material Carousel Slider.

Guys here is the updated Material Carousel for Angular 12 : Angular 11 Material Carousel

Angular Material Carousel Slider

Angular 16 came and if you are new then you must check below two links:

  1. Angular12 Basic Tutorials
  2. Angular Free Templates

Here are the basic steps for Angular Material Carousel Slider and please follow carefully:

1. Here is the command, you need to run into your command prompt to get angular material modules:

ng add @angular/material
npm i @ngmodule/material-carousel

2. Here is the code, you need to add into your app.module.ts file:

//...
import { MatCarouselModule } from '@ngmodule/material-carousel';
 
@NgModule({
  // ...
  imports: [
    // ...
    MatCarouselModule.forRoot(),
    // ...
  ]
})
export class AppModule {}

3. Here is the code, you need to add into your app.component.ts file:

...
import { MatCarousel, MatCarouselComponent } from '@ngmodule/material-carousel';

export class AppComponent {
   ...
   // Slider Images
   slides = [{'image': 'https://therichpost.com/wp-content/uploads/2021/02/Vuejs-Fashion-Ecommerce-Template-Free.png'}, {'image': 'https://therichpost.com/wp-content/uploads/2021/02/angular-11-bootstrap-4.5-Ecommerce-Template-Free.png'},{'image': 'https://therichpost.com/wp-content/uploads/2020/10/Angular-10-Learning-Education-Center-Free-Template-1.png'}, {'image': 'https://therichpost.com/wp-content/uploads/2020/11/Reactjs-Easy-Shop-Free-Template-with-Source-Code.png'}, {'image': 'https://therichpost.com/wp-content/uploads/2021/02/angular-11-bootstrap-4.5-Ecommerce-Template-Free.png'}];

  
}

4. Here is the code, you need to add your app.component.html file:

<h1 style="text-align:center;">Angular 9 Material Carousel Slider</h1>
  
  <mat-carousel
  timings="250ms ease-in"
  [autoplay]="true"
  interval="5000"
  color="accent"
  maxWidth="auto"
  proportion="25"
  slides="5"
  [loop]="true"
  [hideArrows]="false"
  [hideIndicators]="false"
  [useKeyboard]="true"
  [useMouseWheel]="false"
  orientation="ltr"
>
  <mat-carousel-slide
    #matCarouselSlide
    *ngFor="let slide of slides; let i = index"
    [image]="slide.image"
    overlayColor="#00000040"
    [hideOverlay]="false"
  ></mat-carousel-slide>
</mat-carousel>

Now we are done friends. If you have any kind of query or suggestion or requirement then feel free to comment below.

Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.

I will appreciate that if you will tell your views for this post. Nothing matters if your views will be good or bad because with your views, I will make my next posts more good and helpful.

Jassa

Thank you

You may also like

75 comments

rajitha July 2, 2020 - 6:21 am

ERROR in The target entry-point “@ngmodule/material-carousel” has missing dependencies:
– @angular/core
– @angular/platform-browser
– @angular/animations
– @angular/cdk/a11y
– @angular/common
– rxjs
– rxjs/operators
– @angular/material/button
– @angular/material/icon
– @angular/material/core
– @angular/compiler/src/core
im getting this error while adding it to app module

Reply
Ajay Malhotra July 2, 2020 - 7:34 am

Please try this also:
npm install –save @angular/material
npm install –save @angular/animations

Reply
Nrusinha Prasad Mahapatra July 10, 2020 - 3:38 pm

I don’t see anything on my screen. Totally blank. Did I do something wrong? Do we have to do anything else?

Reply
Ajay Malhotra July 11, 2020 - 5:16 am

After cli update and angular 10 came and I also going to update this and thank you your reply.

Reply
Karen July 16, 2020 - 5:08 am

Thank you and it worked well.

Reply
Ajay Malhotra July 16, 2020 - 5:09 am

Thank you karen.

Reply
Inga August 4, 2020 - 1:39 pm

how we can add more than 1 item on one slide? for example, if I want to have a multi-items slider

Reply
tohedul August 6, 2020 - 4:30 am

Hi, how can I change slider transition animation?

Reply
Ajay Malhotra August 6, 2020 - 4:34 am

Hi, you want to change the slider animate timings?

Reply
Yves Fontaine August 11, 2020 - 8:49 am

I have issue with the size of my carousel
It’s within a router outlet and it doesn’t display correctly, the size is too big and overwhelms the navigator. As a consequence the arrow on the right is not displayed.
The other issue is that the image used in the carousel are too bigs sometimes and they don’t fully display.

Reply
Ajay Malhotra August 11, 2020 - 8:55 am

You can do this with custom styles and for images, you can decrease the image size.
Thanks

Reply
Yves Fontaine August 11, 2020 - 9:16 am

You can only display 1920×480 size image ?

Reply
Ajay Malhotra August 11, 2020 - 9:22 am

yes

Reply
teja_ch August 16, 2020 - 3:14 am

How can I display text over the slide??

Reply
Ajay Malhotra August 16, 2020 - 6:08 am

HI, I will share the working post link. Thanks

Reply
YHuiC August 20, 2020 - 3:19 pm

Hi, it this material carousel support click event? for example, after clicks image 1 and will navigate to another page. Appreciated your help!

Reply
Ajay Malhotra August 20, 2020 - 3:21 pm

Yes and this link will help you to add custom button on every slider.
Thanks

Reply
YHuiC August 21, 2020 - 12:24 am

Hi, thanks for your reply. By the way, which link i can refer.

Reply
Sahith August 24, 2020 - 6:18 pm

Hi I am not getting the arrows and indicators are not middle of the carousel.
Could you help me

Reply
Ajay Malhotra August 25, 2020 - 3:36 am

Hi, you are not getting material carousel slider like my example?

Reply
Sahith August 25, 2020 - 4:10 am

I am not getting the icons “->” and “<-". The slide indicators are not in the middle of page.

Reply
YHuiC August 28, 2020 - 9:52 am

thank you!

Reply
eric August 25, 2020 - 4:05 pm

Is this written for v10 or 9?

Reply
Ajay Malhotra August 25, 2020 - 4:07 pm

Yes this is for both. Thanks

Reply
Mohit Singh August 28, 2020 - 12:25 am

i have saved the image to the base64 string format in database but on retrieval i am unable to bind it to the carousel.
my code of carousel is

above line of code does not work
but when i simply write
out of the

this code shows the image on the screen.
Please help.

Reply
Ajay Malhotra August 28, 2020 - 4:09 am

Hi, can you please send me your image src or you can email me on therichposts@gmail.com

Thanks

Reply
Kaye September 2, 2020 - 4:53 pm

Hello. I’m getting a word “back and forward arrow” instead of an icon, Any thoughts?

Reply
Ajay Malhotra September 2, 2020 - 4:55 pm

Yes, you can do with custom script code.
Thanks

Reply
Kaye September 2, 2020 - 5:43 pm

I’m a newbie to programming. Do you have an example?

Reply
Ajay Malhotra September 2, 2020 - 5:48 pm

I will update you and if you are subscribed then you will get noticed. Thanks.

Click bell icon bottom left.

Reply
Kaye September 2, 2020 - 8:56 pm

Done

Ajay Malhotra September 3, 2020 - 4:08 pm

You need to import below into your app.module.ts file:
import {MatIconModule} from ‘@angular/material/icon’;

Thanks

Reply
Kaye September 3, 2020 - 5:41 pm

I did that and nothing happens 🙂
Thanks for your reply

Reply
Ajay Malhotra September 3, 2020 - 5:57 pm

🙂

Reply
Kaye September 3, 2020 - 6:22 pm

Am I missing anything?

teja_ch September 3, 2020 - 2:49 pm

1).how can i use proportion=25 in laptop view and proportion=80 in mobile view ?

2).and I am getting the following warning-
Warning: Entry point ‘@ngmodule/material-carousel’ contains deep imports into ‘C:/Users/teja/Desktop/jgd_courses-sample/jgd/node_modules/@angular/compiler/src/core’. This is probably not a problem, but may cause the compilation of entry points to be out of order.

3).and error in console:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: ‘undefined’. Current value: ‘[object Object]’.
at throwErrorIfNoChangesMode (core.js:5467)
at bindingUpdated (core.js:13112)
at Module.ɵɵproperty (core.js:13907)
at MatCarouselComponent_li_4_Template (ngmodule-material-carousel.js:55)
at executeTemplate (core.js:7447)
at refreshView (core.js:7316)
at refreshEmbeddedViews (core.js:8408)
at refreshView (core.js:7340)
at refreshComponent (core.js:8454)
at refreshChildComponents (core.js:7109)

please resolve these three isuues

Reply
Ajay Malhotra September 3, 2020 - 3:59 pm

I need to see your code.

Reply
Navneet September 11, 2020 - 8:49 pm

Dear Ajay,
How can I increase the size of the carousel. Like a full page carousel slider.
Please guide.
Thank You

Reply
Ajay Malhotra September 12, 2020 - 4:18 am

Hi and this is already full width slider.
Thanks

Reply
Navneet September 12, 2020 - 3:27 pm

I want this slider to cover full height of the page.

Reply
Ajay Malhotra September 12, 2020 - 3:29 pm

Okay means full page slider?

Reply
Navneet September 12, 2020 - 3:33 pm

Yes,

Also if you can provide a proper easy to.underatand angular flex tutorial, that will be a great help.

Navneet September 12, 2020 - 3:32 pm

The carousel is inside router outlet.

I am sharing the code, please help.
app.component.html

app.component.css

mat-sidenav-container, mat-sidenav-content,mat-sidenav {

height: 100%;
}

mat-sidenav {
width: 250px;
}

welcome.component.html

app-routing.module.ts
import { NgModule } from ‘@angular/core’;
import { Routes, RouterModule } from ‘@angular/router’;

import { AppComponent } from ‘src/app/app.component’;
import { WelcomeComponent } from ‘src/app/welcome/welcome.component’;

const routes: Routes = [
{ path: ”, component: WelcomeComponent }
];

@NgModule({
declarations: [],
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: []
})
export class AppRoutingModule { }

Reply
Ajay Malhotra September 12, 2020 - 3:34 pm

Don’t worry, I will update you soon.

Reply
Navneet September 12, 2020 - 3:45 pm

Ok thanks

Reply
Mercy October 6, 2020 - 4:42 am

Thank You so much,it worked well. I Appreciate your work.

Reply
Ajay Malhotra October 6, 2020 - 4:44 am

Thank you 🙂

Reply
Costantino November 26, 2020 - 6:44 pm

Hello! thanks for the tutorial, I’m struggling right now because I am trying to build a Carousel of Material Cards in Angular 10, but I can’t find nothing.
I’d like to know if is it possible to use cards instead of images for this carousel..
Thanks in advance.
Kind regards,
Costantino

Reply
Ajay Malhotra November 27, 2020 - 4:12 am

Welcome and I will update you on this.

Reply
bilal khan December 16, 2020 - 5:32 pm

Is it possible to add router-link or click event on the images of the slider? if yes then please tell me how?

Reply
Ajay Malhotra December 17, 2020 - 4:10 am

Yes and I will update you on this.
Thanks

Reply
mayur December 17, 2020 - 6:30 am

there is no output event like (drag)=drageslide($event)

Reply
Ajay Malhotra December 17, 2020 - 6:31 am

I did not get your query?

Reply
mayur December 17, 2020 - 6:58 am

– i make click on element but when i drag slide i need to prevent click event.
-how to show 3.5 item in slide.

Reply
Ajay Malhotra December 17, 2020 - 7:01 am

Okay, I will update you.

Reply
mayur December 17, 2020 - 7:09 am

Thanks.

saim January 5, 2021 - 1:53 pm

How can I change the arrow icons with another mat icons??

Reply
Ajay Malhotra January 5, 2021 - 4:19 pm

With CSS you can do that.

Reply
Hue January 20, 2021 - 2:43 am

My error:
Error: src/app/product/product.component.html:53:1 – error TS2322: Type ‘string’ is not assignable to type ‘number’.

53 interval=”5000″
~~~~~~~~~~~~~~~

src/app/product/product.component.ts:15:18
15 templateUrl: ‘./product.component.html’,
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ProductComponent.
src/app/product/product.component.html:56:1 – error TS2322: Type ‘string’ is not assignable to type ‘number’.

56 proportion=”25″
~~~~~~~~~~~~~~~

src/app/product/product.component.ts:15:18
15 templateUrl: ‘./product.component.html’,
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ProductComponent.
src/app/product/product.component.html:57:1 – error TS2322: Type ‘string’ is not assignable to type ‘number’.

57 slides=”5″
~~~~~~~~~~

src/app/product/product.component.ts:15:18
15 templateUrl: ‘./product.component.html’,
~~~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component ProductComponent.
My english is not good. I looking forward to hearing from you. Thanks!

Reply
ashima April 8, 2021 - 2:59 pm

Hi,
The images are not displayed. any clue?

Reply
Ajay Malhotra April 8, 2021 - 3:41 pm

you can add new images.

Reply
Sanjay Gohel May 6, 2021 - 6:42 am

First of all Thank you very much of very good explanation …
I have question about ….On load page can I jump to specific slide? like I have 10 images but I want to slide to 3rd on load page….I hope you got my point.

Reply
Ajay Malhotra May 6, 2021 - 6:45 am

Yes I got your point and I will update you on this.
Thanks.

Reply
vignesh July 7, 2021 - 10:29 am

I need to show 4 images at the time ..any solution plz

Reply
Ajay Malhotra July 7, 2021 - 10:31 am

Okay and I will update you thanks.

Reply
Sebastian lopez November 8, 2021 - 4:44 pm

¿como puedo cambiar el tamaño de 1942 x 480?

Reply
Vitthal Walunj January 3, 2022 - 12:46 pm

Is it useful with angular 13?

Reply
Ajay Malhotra January 5, 2022 - 3:47 am

Yes

Reply
Eman Mohamed February 16, 2022 - 7:15 am

1. If ‘mat-carousel’ is an Angular component and it has ‘useMouseWheel’ input, then verify that it is part of this module.
2. If ‘mat-carousel’ is a Web Component then add ‘CUSTOM_ELEMENTS_SCHEMA’ to the ‘@NgModule.schemas’ of this component to suppress this message.
3. To allow any property add ‘NO_ERRORS_SCHEMA’ to the ‘@NgModule.schemas’ of this component.

19 [useMouseWheel]=”false”
~~~~~~~~~~~~~~~~~~~~~~~

src/app/auth/login/login/login.component.ts:6:16
6 templateUrl: ‘./login.component.html’,
~~~~~~~~~~~~~~~~~~~~~~~~
Error occurs in the template of component LoginComponent.

Reply
Ajay Malhotra February 16, 2022 - 7:48 am

I will check and update you, thanks.

Reply
Romal June 1, 2022 - 4:17 am

how to add a click event in mat craousel slide

Reply
shubham bhujbal November 4, 2022 - 6:15 am

Property ‘slides’ does not exist on type ‘AppComponent’.ngtsc(2339)
app.component.ts(3, 47): Error occurs in the template of component AppComponent.

Reply

Leave a Comment

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