简体   繁体   English

将图像传递到Angular UI Bootstrap Carousel

[英]Passing images to Angular UI Bootstrap Carousel

I am using the Angular UI Bootstrap carousel in a project and I would like to pass own images to this slider. 我在项目中使用Angular UI Bootstrap轮播,我想将自己的图像传递到此滑块。 This is my code for the Carousel Controller: 这是我的轮播控制器代码:

.controller('CarouselCtrl', function ($scope) {
  $scope.myInterval = 2000;
  var slides = $scope.slides = [];
  $scope.addSlide = function() {
    var newWidth = 1 + slides.length + 1;
    slides.push({
      image: '../img' + newWidth,
      text: ['More','Extra','Lots of','Surplus'][slides.length % 4] + ' ' +
      ['Cats', 'Kittys', 'Felines', 'Cutes'][slides.length % 4]
    });
  };
  for (var i=0; i<4; i++) {
    $scope.addSlide();
  }
})

I understand that a new array is initialised and the function addSlide adds each image to the array and iterates throught this array; 我知道初始化了一个新数组,函数addSlide将每个图像添加到该数组并遍历该数组; however, I just want to change the origin of the images to the image folder in the project and it is not working by now, the images are not displayed. 但是,我只想将图像的原点更改为项目中的图像文件夹,并且目前无法正常工作,因此无法显示图像。 The img folder is one folder above the .js-file with the Carousel Controller. img文件夹是带有Carousel Controller的.js文件上方的一个文件夹。 So I would be very happy for any hint, thanks! 因此,如果有任何提示,我将非常高兴,谢谢!

If you want the images to be called correctly, it is best to start with / (instead of ../) and understand that it is starting at your root web directory. 如果要正确调用图像,则最好以/ (而不是../)开头,并了解它是从根Web目录开始的。

So the correct location might be: 因此正确的位置可能是:

slides.push({
  image: '/images/img' + newWidth,
  text: ['More','Extra','Lots of','Surplus'][slides.length % 4] + ' ' +
    ['Cats', 'Kittys', 'Felines', 'Cutes'][slides.length % 4]
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM