An open API service indexing awesome lists of open source software.

https://github.com/vitalii-andriiovskyi/ngx-owl-carousel-o

owl-carousel for Angular >=6
https://github.com/vitalii-andriiovskyi/ngx-owl-carousel-o

Last synced: 15 days ago
JSON representation

owl-carousel for Angular >=6

Awesome Lists containing this project

README

        

# ngx-owl-carousel-o

## Compatibility

ngx-owl-carousel-o | Angular
------------------------|--------
19.x.x | 19.x.x
18.x.x (latest `18.0.1`)| 18.x.x
17.x.x (latest `17.0.1`)| 17.x.x
16.x.x (latest `16.0.1`)| 16.x.x
15.x.x (latest `15.0.2`)| 15.x.x
14.x.x (latest `14.0.2`)| 14.x.x
7.x.x (latest `7.0.5`) | 13.x.x
6.x.x (latest `6.0.3`) | 12.x.x
5.x.x (latest `5.1.2`) | 11.x.x
4.x.x (latest `4.1.2`) | 10.x.x
3.x.x (latest `3.1.1`) | 9.x.x
2.x.x (latest `2.1.2`) | 8.x.x
1.x.x (latest `1.2.1`) | 7.x.x
0.x.x (latest `0.1.2`) | 6.x.x

[CHANGELOG](./CHANGELOG.md)

## Table of Contents

- [Get started](#get-started)
- [Setting custom slides ids](#setting-custom-slides-ids)
- [Options](#options)
- [How to refresh the carousel if options change](#refreshing-the-carousel-if-options-change)
- [Tag `` in the slide. Directive `owlRouterLink`](#owlRouterLink)
- [Events](#events)
- [Plugins](#plugins)
- [Tips](#tips)
- [ReferenceError: Event is not defined](#referenceError-event-is-not-defined)
- [Using `ngx-owl-carousel-o` slide data in custom code](#using-internal-slide-data)
- [Issue: `autoplay` doesn't stay paused when user opens `mat-menu`](#issue-autoplay-doesnt-stay-paused-when-user-opens-mat-menu)

## Get started

1. Run `yarn add ngx-owl-carousel-o` or `npm install ngx-owl-carousel-o`.
2. Add styles (one of these variants).

- `angular.json`:

```json
"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.sass" or "src/styles.css"
],
```

- `src/styles.sass` or `src/styles.scss`:

```sass
@import 'ngx-owl-carousel-o/lib/styles/scss/owl.carousel';
@import 'ngx-owl-carousel-o/lib/styles/scss/owl.theme.default';
```

3. Import `RouterModule` and `Routes` into `AppModule` unless they are imported.
4. Import `BrowserAnimationsModule` into `AppModule` unless it is imported.
5. Import `CarouselModule` into a module which declares a component intended to have a carousel.

```typescript
import { CarouselModule } from 'ngx-owl-carousel-o';
@NgModule({
imports: [ CarouselModule ],
declarations: [ CarouselHolderComponent ]
})
export class SomeModule { }
```

6. Add to needed component `customOptions` or named in different way object with options for the carousel:

```typescript
import { OwlOptions } from 'ngx-owl-carousel-o';
import { Component } from "@angular/core";
@Component({
selector: '....',
templateUrl: 'carousel-holder.component.html'
})
export class CarouselHolderComponent {
customOptions: OwlOptions = {
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
}
}
```

7. Add html-markup to the template of the component (in this case, add it to `carousel-holder.component.html`):

```html

Some tags before


Slide 1
Slide 2
Slide 3

Some tags after

```

or

```html

Some tags before






Some tags after

```

**NOTE**: Each slide has an `id`. If it isn't supplied like in the first example given to p. 7, the code generates it automatically and expose one when the event `translated` fires. Info about this event is below. Follow the link [event `translated`](#translated).

**NOTE**: Custom `id` must have the type `string`.

**NOTE**: Using **ngx-owl-carousel-o** with options `animateOut` and `animateIn` requires adding `animate.css`. Steps are the following:

1. `yarn add animate.css` or `npm install animate.css`.
2. Add styles to `angular.json`:

```json
"styles": [
"node_modules/animate.css/animate.min.css"
],
```

## Setting custom slides ids

It's possible to set own id to every slide.

> Every `id` must have the type `string`. Otherwise, slides won't get ids what will cause one problem, which appears when the developer uses the option `responsive`. Slides won't be shown when the width of the screen changes and the carousel has to apply new settings according to the defined breakpoint. This is because the code uses ids of slides in order to assign new data to slides. So if you change the width of the screen and slides disappear, there could be the problem with setting `id`.
> If `id`s aren't set explicitly, they will be created automatically.

The example of setting ids:

```html

Some tags before






Some tags after

```

## Options

**ngx-owl-carousel-o** uses the same options as Owl Carousel. Explanations of meanings and the usage of options are in [Owl Carousel Documentation](https://owlcarousel2.github.io/OwlCarousel2/docs/api-options.html).

**NOTE**: **ngx-owl-carousel-o** has the different usage of some of them. Mostly this is about options which require setting `data-` attributes to DOM-elements and which set names of classes and tags in the HTML-markup. The usage of these options is explained below.

Options which require setting `data-` attributes are:

- [merge](#merge).
- [dotsData](#dotsdata).
- [URLhashListener](#urlhashlistener).
- [lazyLoad](#lazyload).

### merge

The original Owl Carousel requires setting `data-merge` to each slide besides setting `merge=true`. In this lib `data-merge` is changed to `dataMerge` , which is the `@Input` property of the `` directive. The way of setting it is:

```html
Slide text or HTML markup
```

the `number` must be 1, 2, 3 or any other integer numbers. If `dataMerge` isn't provided, its value will be 1 (this is the default value).

### autoWidth

The option `autoWidth=true` is working if user sets the `@Input` prop `width` to `` directive. The example:

```html
Slide text or html markup
```

When the `width` isn't provided for a certain slide and is provided for other slides, firstly it will be 0 (this is the default value). At the end it will be calculated as (width of carousel)/(items) (e.g. `carouselWidth=1200` and `items=4`, the width of the slide will be `1200/4=300`).

In other words, the width of the slide with unprovided `width` will be set according to how much space in visible carousel window the slide must take. E.g. if there must be 2 visible slides, the width of the item will be half of the carousel window.

### responsiveBaseElement

The option `responsiveBaseElement` doesn't work. In the original Owl Carousel, all responsive breakpoints are corresponding to window width. Here they are corresponding to the width of the element `