javascript - json 数据上的 Angular js 中的 Slick Carousel 不起作用

标签 javascript angularjs

我使用这个程序 github.com/vasyabigi/angular-slick .它不适用于动态数据。它只适用于静态数据。在动态数据中,它显示垂直图像而不是水平图像,没有轮播。请帮助我。 这是我的指令

directive('slick',function($timeout) {  return {
restrict: "AEC",
scope: {
  initOnload: "@",
  data: "=",
  currentIndex: "=",
  accessibility: "@",
  arrows: "@",
  autoplay: "@",
  autoplaySpeed: "@",
  centerMode: "@",
  centerPadding: "@",
  cssEase: "@",
  dots: "@",
  draggable: "@",
  easing: "@",
  fade: "@",
  infinite: "@",
  lazyLoad: "@",
  onBeforeChange: "@",
  onAfterChange: "@",
  onInit: "@",
  onReInit: "@",
  pauseOnHover: "@",
  responsive: "&",
  slide: "@",
  slidesToShow: "@",
  slidesToScroll: "@",
  speed: "@",
  swipe: "@",
  touchMove: "@",
  touchThreshold: "@",
  vertical: "@"
},
link: function(scope, element, attrs) {
  var initializeSlick, isInitialized;
  initializeSlick = function() {
    return $timeout(function() {
      var currentIndex, slider;
      slider = $(element);
      if (scope.currentIndex != null) {
        currentIndex = scope.currentIndex;
      }
      slider.slick({
        accessibility: scope.accessibility !== "false",
        arrows: scope.arrows !== "false",
        autoplay: scope.autoplay === "true",
        autoplaySpeed: scope.autoplaySpeed != null ? parseInt(scope.autoplaySpeed, 10) : 3000,
        centerMode: scope.centerMode === "true",
        centerPadding: scope.centerPadding || "50px",
        cssEase: scope.cssEase || "ease",
        dots: scope.dots === "true",
        draggable: scope.draggable !== "false",
        easing: scope.easing || "linear",
        fade: scope.fade === "true",
        infinite: scope.infinite !== "false",
        lazyLoad: scope.lazyLoad || "ondemand",
        onBeforeChange: scope.onBeforeChange || null,
        onAfterChange: function(sl, index) {
          if (scope.onAfterChange) {
            scope.onAfterChange();
          }
          if (currentIndex != null) {
            return scope.$apply(function() {
              currentIndex = index;
              return scope.currentIndex = index;
            });
          }
        },
        onInit: function(sl) {
          if (scope.onInit) {
            scope.onInit();
          }
          if (currentIndex != null) {
            return sl.slideHandler(currentIndex);
          }
        },
        onReInit: scope.onReInit || null,
        pauseOnHover: scope.pauseOnHover !== "false",
        responsive: scope.responsive() || null,
        slide: scope.slide || "div",
        slidesToShow: scope.slidesToShow != null ? parseInt(scope.slidesToShow, 10) : 1,
        slidesToScroll: scope.slidesToScroll != null ? parseInt(scope.slidesToScroll, 10) : 1,
        speed: scope.speed != null ? parseInt(scope.speed, 10) : 300,
        swipe: scope.swipe !== "false",
        touchMove: scope.touchMove !== "false",
        touchThreshold: scope.touchThreshold ? parseInt(scope.touchThreshold, 10) : 5,
        vertical: scope.vertical === "true"
      });
      return scope.$watch("currentIndex", function(newVal, oldVal) {
        if ((currentIndex != null) && (newVal != null) && newVal !== currentIndex) {
          return slider.slickGoTo(newVal);
        }
      });
    });
  };
  if (scope.initOnload) {
    isInitialized = false;
    return scope.$watch("data", function(newVal, oldVal) {
      if ((newVal != null) && !isInitialized) {
        initializeSlick();
        return isInitialized = true;
      }
    });
  } else {
    return initializeSlick();
  }
}  };});

最佳答案

有一个属性叫做init-onLoad,让它为真即可。

<slick init-onload=true data="awesomeThings">
  ...
</slick>

关于javascript - json 数据上的 Angular js 中的 Slick Carousel 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25162099/

相关文章:

javascript - ASP DropDownList 样式设计困难

javascript - 如何从 Javascript 调用 PHP 文件并将数据从 PHP 返回到 Javascript

javascript - 自定义 Angular 指令、控制台日志、DOM 更新、屏幕不

javascript - 使用选择下拉列表的性别 Angular 过滤器

AngularJS - 获取已定义路由的列表 - $routeProvider

javascript - Webix 日历插件禁用 Android 上的滚动和滑动

javascript - 如何按带有时间戳的日期分组? ( Angular )

javascript - Angularjs 获取 json 在谷歌地图中不起作用

javascript - Angular 1.x : attribute of an object inside data-ng-repeat is set as a string, 不是对象

javascript - Highcharts jQuery 渲染问题 - 所有浏览器