Angular 9 Material Carousel Slider

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

Comments

75 responses to “Angular 9 Material Carousel Slider”

  1. rajitha Avatar
    rajitha

    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

    1. Ajay Malhotra Avatar

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

  2. Nrusinha Prasad Mahapatra Avatar
    Nrusinha Prasad Mahapatra

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

    1. Ajay Malhotra Avatar

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

  3. Karen Avatar
    Karen

    Thank you and it worked well.

    1. Ajay Malhotra Avatar
  4. Inga Avatar
    Inga

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

  5. tohedul Avatar
    tohedul

    Hi, how can I change slider transition animation?

    1. Ajay Malhotra Avatar

      Hi, you want to change the slider animate timings?

  6. Yves Fontaine Avatar
    Yves Fontaine

    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.

    1. Ajay Malhotra Avatar

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

      1. Yves Fontaine Avatar
        Yves Fontaine

        You can only display 1920×480 size image ?

  7. teja_ch Avatar
    teja_ch

    How can I display text over the slide??

    1. Ajay Malhotra Avatar

      HI, I will share the working post link. Thanks

  8. YHuiC Avatar
    YHuiC

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

    1. Ajay Malhotra Avatar

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

      1. YHuiC Avatar
        YHuiC

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

  9. Sahith Avatar
    Sahith

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

    1. Ajay Malhotra Avatar

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

      1. Sahith Avatar
        Sahith

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

    2. YHuiC Avatar
      YHuiC

      thank you!

  10. eric Avatar
    eric

    Is this written for v10 or 9?

    1. Ajay Malhotra Avatar

      Yes this is for both. Thanks

  11. Mohit Singh Avatar
    Mohit Singh

    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.

    1. Ajay Malhotra Avatar

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

      Thanks

  12. Kaye Avatar
    Kaye

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

    1. Ajay Malhotra Avatar

      Yes, you can do with custom script code.
      Thanks

      1. Kaye Avatar
        Kaye

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

        1. Ajay Malhotra Avatar
          Ajay Malhotra

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

          Click bell icon bottom left.

    2. Ajay Malhotra Avatar

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

      Thanks

      1. Kaye Avatar
        Kaye

        I did that and nothing happens 🙂
        Thanks for your reply

          1. Kaye Avatar
            Kaye

            Am I missing anything?

  13. teja_ch Avatar
    teja_ch

    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

    1. Ajay Malhotra Avatar

      I need to see your code.

  14. Navneet Avatar
    Navneet

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

    1. Ajay Malhotra Avatar

      Hi and this is already full width slider.
      Thanks

      1. Navneet Avatar
        Navneet

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

        1. Ajay Malhotra Avatar

          Okay means full page slider?

          1. Navneet Avatar
            Navneet

            Yes,

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

  15. Navneet Avatar
    Navneet

    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 { }

    1. Ajay Malhotra Avatar

      Don’t worry, I will update you soon.

      1. Navneet Avatar
        Navneet

        Ok thanks

  16. Mercy Avatar
    Mercy

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

  17. Costantino Avatar
    Costantino

    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

    1. Ajay Malhotra Avatar

      Welcome and I will update you on this.

  18. bilal khan Avatar
    bilal khan

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

    1. Ajay Malhotra Avatar

      Yes and I will update you on this.
      Thanks

  19. mayur Avatar
    mayur

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

    1. Ajay Malhotra Avatar

      I did not get your query?

      1. mayur Avatar
        mayur

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

        1. Ajay Malhotra Avatar

          Okay, I will update you.

          1. mayur Avatar
            mayur

            Thanks.

  20. saim Avatar
    saim

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

    1. Ajay Malhotra Avatar

      With CSS you can do that.

  21. Hue Avatar
    Hue

    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!

  22. ashima Avatar
    ashima

    Hi,
    The images are not displayed. any clue?

    1. Ajay Malhotra Avatar

      you can add new images.

  23. Sanjay Gohel Avatar
    Sanjay Gohel

    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.

    1. Ajay Malhotra Avatar

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

  24. vignesh Avatar
    vignesh

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

    1. Ajay Malhotra Avatar

      Okay and I will update you thanks.

  25. Sebastian lopez Avatar
    Sebastian lopez

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

  26. Vitthal Walunj Avatar
    Vitthal Walunj

    Is it useful with angular 13?

  27. Eman Mohamed Avatar
    Eman Mohamed

    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.

    1. Ajay Malhotra Avatar

      I will check and update you, thanks.

  28. Romal Avatar
    Romal

    how to add a click event in mat craousel slide

  29. shubham bhujbal Avatar
    shubham bhujbal

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

Leave a Reply

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

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