-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
71 lines (54 loc) · 1.49 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
// step 1 in example
var sliderApp = angular.module('sliderApp',['ngAnimate']);
sliderApp.directive('slider', function($timeout) {
return {
restrict: 'AE',
replace: true,
scope: {
images: '='
},
link: function(scope, elem, attrs) {
scope.currentIndex = 0; // Initially the index is at the first image
scope.next = function() {
scope.currentIndex < scope.images.length - 1 ? scope.currentIndex++ : scope.currentIndex = 0;
};
scope.prev = function() {
scope.currentIndex > 0 ? scope.currentIndex-- : scope.currentIndex = scope.images.length - 1;
};
// step 4b
scope.$watch('currentIndex', function() {
scope.images.forEach(function(image) {
image.visible = false; // make every image invisible
});
scope.images[scope.currentIndex].visible = true; // make the current image visible
});
},
templateUrl: 'directives/slider.html'
};
});
// step 2 in example this is setting our images for the slide show
sliderApp.controller('SliderController', function($scope) {
$scope.images = [{
src: 'img1.jpg',
title: 'Pic 1',
visible: true
}, {
src: 'img2.jpg',
title: 'Pic 2',
visible: true
}, {
src: 'img3.jpg',
title: 'Pic 3',
visible: true
}, {
src: 'img4.jpg',
title: 'Pic 4',
visible: true
}, {
src: 'img5.jpg',
title: 'Pic 5',
visible: true
}];
});
// step 4 pretty sure this is in the wrong place