Search code examples
angularowl-carousel

Angular 9: ngx-owl-carouel not rendered because of "Cannot read property '$owl' of undefined" error


I'm trying to implement a card slider into my project. Actually, I cannot figure out why ngx-owl-carousel doesn't get rendered and gives an annoying problem. I followed step by step the guide on npm and tried to put inside the Card example on Angular Docs.

<owl-carousel
    [options]="{items: 3, dots: false, navigation: false}" [items]="professionals"
    [carouselClasses]="['owl-theme', 'row', 'sliding']">
    <div class="item" *ngFor="let professional of professionals;let i = index">
    <mat-card class="example-card">
        <mat-card-header>
        <div mat-card-avatar class="example-header-image"></div>
        <mat-card-title>Shiba Inu</mat-card-title>
        <mat-card-subtitle>Dog Breed</mat-card-subtitle>
        </mat-card-header>
        <img mat-card-image src="https://material.angular.io/assets/img/examples/shiba2.jpg"
            alt="Photo of a Shiba Inu">
        <mat-card-content>
        <p>
            The Shiba Inu is the smallest of the six original and distinct spitz breeds of dog from Japan.
            A small, agile dog that copes very well with mountainous terrain, the Shiba Inu was originally
            bred for hunting.
        </p>
        </mat-card-content>
        <mat-card-actions>
        <button mat-button>LIKE</button>
        <button mat-button>SHARE</button>
        </mat-card-actions>
    </mat-card>
    </div>
</owl-carousel>

I also imported properly JQuery and NGX Carousel (stylesheets too):

"styles": [
    "src/styles.scss",
    "./node_modules/owl.carousel/dist/assets/owl.carousel.css",
    "./node_modules/owl.carousel/dist/assets/owl.theme.default.css"
],
"scripts": [
   "./node_modules/jquery/dist/jquery.min.js",
   "./node_modules/owl.carousel/dist/owl.carousel.js"
]

But into the browser it keeps throw this error (even without any object inside).

Browser Console Error


Solution

  • Remove [items]="professionals from owl-carousel tag. It is required only if image array is changing dynamically.