2
Hello, use Angularjs and wanted to put it to change the slides from 10 in 10 sec. I’ve tried a few codes and I couldn’t. Anybody got a tip? Here comes my controller.
(function () {
'use strict';
angular.module('scases')
.controller('BannerCtrl', function ($scope) {
$scope.slides = [
{ image: 'images/teste.jpg', description: 'Image 00', interval: 3000 },
{ image: 'images/zenfone.jpg', description: 'Image 01', interval: 3000 },
{ image: 'images/lg.jpg', description: 'Image 02', interval: 3000 },
{ image: 'images/iphone4.jpg', description: 'Image 03', interval: 3000 },
{ image: 'images/iphone5.jpg', description: 'Image 04', interval: 3000 }
];
$scope.direction = 'left';
$scope.currentIndex = 0;
$scope.setCurrentSlideIndex = function (index) {
$scope.direction = (index > $scope.currentIndex) ? 'left' : 'right';
$scope.currentIndex = index;
};
$scope.isCurrentSlideIndex = function (index) {
return $scope.currentIndex === index;
};
$scope.prevSlide = function () {
$scope.direction = 'left';
$scope.currentIndex = ($scope.currentIndex < $scope.slides.length - 1) ? ++$scope.currentIndex : 0;
};
$scope.nextSlide = function () {
$scope.direction = 'right';
$scope.currentIndex = ($scope.currentIndex > 0) ? --$scope.currentIndex : $scope.slides.length - 1;
};
}).animation('.slide-animation', function () {
return {
beforeAddClass: function (element, className, done) {
var scope = element.scope();
if (className == 'ng-hide') {
var finishPoint = element.parent().width();
if (scope.direction !== 'right') {
finishPoint = -finishPoint;
}
TweenMax.to(element, 0.5, { left: finishPoint, onComplete: done });
}
else {
done();
}
},
removeClass: function (element, className, done) {
var scope = element.scope();
if (className == 'ng-hide') {
element.removeClass('ng-hide');
var startPoint = element.parent().width();
if (scope.direction === 'right') {
startPoint = -startPoint;
}
TweenMax.fromTo(element, 0.5, { left: startPoint }, { left: 0, onComplete: done });
}
else {
done();
}
}
};
}
)
}) ();
I tried the way you put it there, and it still doesn’t work. It doesn’t give any error in the console. but it is as if the function does not work.
– Biellx
angular.js:13550 Typeerror: $Scope.swapSlide is not a Function
– Biellx
@Biellx In my reply, click Run Code Snippet. If it works, the problem is probably in your local test.
– OnoSendai