I am troubling with owlCarousel2 slider using angularjs.
My app.js below.
var app = angular.module('plunker', []);
this is my controller
app.controller('MainCtrl', function($scope) {
**Item array which are showing in slide.**
$scope.items = [1,2,3,4,5,6,7,8,9,10]
$scope.addItem = function(arr, $event) {
$event.preventDefault();
arr.push(arr[arr.length - 1] +1);
var firstOwl = $("#first").data('owlCarousel');
firstOwl.addItem("<p>" + arr[arr.length - 1] + "</p>");
}
}).directive("owlCarousel", function() {
return {
restrict: 'E',
transclude: false,
link: function (scope) {
scope.initCarousel = function(element) {
// provide any default options you want
var defaultOptions = {
};
var customOptions = scope.$eval($(element).attr('data-options'));
// combine the two options objects
for(var key in customOptions) {
defaultOptions[key] = customOptions[key];
}
// init carousel
var curOwl = $(element).data('owlCarousel');
if(!angular.isDefined(curOwl)) {
$(element).owlCarousel(defaultOptions);
}
scope.cnt++;
};
}
};
})
.directive('owlCarouselItem', [function() {
return {
restrict: 'A',
transclude: false,
link: function(scope, element) {
// wait for the last item in the ng-repeat then call init
if(scope.$last) {
scope.initCarousel(element.parent());
}
}
};
}]);
It is working fine and shows all 10 slides but when I am update item array like below.
$scope.items = [1,2,3,4,5,6,7,8,9,10,11,12];
$("#owl-demo").trigger('refresh.owl.carousel');
After that 12 slide not showing slider showing same as previous.
How can I do so that my slider will update with my ng-repeat array.