Skip to content

Instantly share code, notes, and snippets.

@lazarofl
Created April 17, 2014 21:29
Show Gist options
  • Save lazarofl/11012704 to your computer and use it in GitHub Desktop.
Save lazarofl/11012704 to your computer and use it in GitHub Desktop.
Aplica uma diretiva para executar o Owl Carousel
var app = angular.module('app', []);
app.controller("ListagemController", function($scope){
$scope.itens = [];
for (var i = 1; i <= 16; i++) {
$scope.itens.push({text: i});
};
})
app.directive('owlcarousel',function(){
var linker = function(scope,element,attr){
//carrega o carrosel
var loadCarousel = function(){
element.owlCarousel({
items : 10, //10 items above 1000px browser width
itemsDesktop : [1000,5], //5 items between 1000px and 901px
itemsDesktopSmall : [900,3], // 3 items betweem 900px and 601px
itemsTablet: [600,2], //2 items between 600 and 0;
itemsMobile : false // itemsMobile disabled - inherit from itemsTablet option
});
}
//aplica as ações para o carrosel
var loadCarouselActions = function(){
angular.element(".owlcarousel_next").click(function(){
element.trigger('owl.next');
})
angular.element(".owlcarousel_prev").click(function(){
element.trigger('owl.prev');
})
angular.element(".owlcarousel_play").click(function(){
element.trigger('owl.play',1000);
})
angular.element(".owlcarousel_stop").click(function(){
element.trigger('owl.stop');
})
}
//toda vez que adicionar ou remover um item da lista ele carrega o carrosel novamente
scope.$watch("itens", function(value) {
loadCarousel(element);
})
//inicia o carrosel
loadCarouselActions();
}
return{
restrict : "A",
link: linker
}
});
@shahzadns
Copy link

your example does not care about removing carousel events, the .destroy() is made for that purpose. you should add a listener for $destroy in this directive, and then call the destroy() function on the carousel element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment