Angular UI-Carousel Bootstrap with Multiple Slides

Asked

Viewed 673 times

1

1 answer

1


I chose to use Owl Carousel in Angularjs.

app.owl.js

angular
.module('appCliente.owl', []);

    function owlCarousel() {
        var directive = {
            restrict: 'E',
            transclude: false,
            link: link
        };
        return directive;

        function link(scope) {
            scope.initCarousel = function (element) {

                console.log('initcarousel');
                var defaultOptions = {};

                var customOptions = scope.$eval($(element).attr('data-options'));
                // combine the two options objects
                for (var key in customOptions) {
                    defaultOptions[key] = customOptions[key];
                }
                // Inicia o OwlCarousel
                var curOwl = $(element).data('owlCarousel');

                if (!angular.isDefined(curOwl)) {
                    $(element).owlCarousel(defaultOptions);
                }
            }
        }
    }

    angular
        .module('appCliente.owl')
        .directive('owlCarousel', owlCarousel);

owlCarousel-Directive.js

angular
    .module('appCliente.owl')
    .directive('owlCarouselItem', owlCarouselItem);

function owlCarouselItem() {
    var directive = {
        link: link,
        restrict: 'A',
        transclude: false
    };
    return directive;

    function link(scope, element) {
        /* Ultimo item do ng-repeat */
        if (scope.$last) {
            console.log('1st element');
            scope.initCarousel(element.parent());
        }
    }
}

Index.html

<!-- OWL Carousel -->
    <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.theme.default.css" rel="stylesheet" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/assets/owl.carousel.css" rel="stylesheet" />

<div class="container">
            <h3 class="text-center alert novo">Novos Mangas</h3>
            <data-owl-carousel class="owl-carousel owl-theme" id="owl-example" data-options="vm.default">
                <div owl-carousel-item="" class="thumb" ng-repeat="manga in vm.novosMangas">
                    <a ui-sref="nav.manga.detalhe({mangasId:manga.id})">
                        <img class="img2" data-ng-src="data:image/jpeg;base64,{{manga.capa}}" ng-if="manga.capa">
                        <img class="img2" src="/app/img/image.JPG" ng-if="!manga.capa">
                    </a>
                    <div class="centered">
                        {{manga.nome}}
                    </div>
                </div>
            </data-owl-carousel>
        </div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.