Angular 9 Material Carousel SliderAngular 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

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

75 thoughts on “Angular 9 Material Carousel Slider”
  1. 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

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

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

  4. 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.

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

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

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

  8. 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.

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

    Click bell icon bottom left.

  10. 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

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

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

  13. Yes,

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

  14. 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

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

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

  17. 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!

  18. 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.

  19. 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.

  20. 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.