我创建了https://angular-ui.github.io/bootstrap/#/carousel
中给出的Angular-UI Carousel但问题是我想将图像更改为我在系统中本地可用的图像。
那么,我怎样才能做到这一点?
这是我的轮播代码的HTML部分。
<div ng-controller="HomeController">
<div style="height: 500px">
<uib-carousel active="active" interval="myInterval" no-wrap="noWrapSlides">
<uib-slide ng-repeat="slide in slides track by slide.id" index="slide.id">
<img ng-src="{{slide.image}}" style="margin:auto;">
</uib-slide>
</uib-carousel>
</div>
</div>
这是控制器代码:
angular.module('portfolioApp', ['ngAnimate','ngTouch','ui.bootstrap'])
.controller('HomeController', ['$scope',function($scope){
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var slides = $scope.slides = [];
var currIndex = 0;
$scope.addSlide = function() {
var newWidth = 600 + slides.length + 1;
slides.push({
image: 'http://lorempixel.com/' + newWidth + '/480',
text: ['Nice image','Awesome photograph','That is so cool','I love that'][slides.length % 4],
id: currIndex++
});
};
$scope.randomize = function() {
var indexes = generateIndexesArray();
assignNewIndexesToSlides(indexes);
};
for (var i = 0; i < 4; i++) {
$scope.addSlide();
}
// Randomize logic below
function assignNewIndexesToSlides(indexes) {
for (var i = 0, l = slides.length; i < l; i++) {
slides[i].id = indexes.pop();
}
}
function generateIndexesArray() {
var indexes = [];
for (var i = 0; i < currIndex; ++i) {
indexes[i] = i;
}
return shuffle(indexes);
}
// http://stackoverflow.com/questions/962802#962890
function shuffle(array) {
var tmp, current, top = array.length;
if (top) {
while (--top) {
current = Math.floor(Math.random() * (top + 1));
tmp = array[current];
array[current] = array[top];
array[top] = tmp;
}
}
return array;
}
}]);
答案 0 :(得分:1)
对于您要添加的每张图片,请致电
slides.push({
image: image_filename,
text: image_text,
id: currIndex++
});
其中image_filename是图像的文件名,image_text是您要在图像上打印的文本