Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 猫头鹰转盘不识别ng重复的元素_Angularjs_Angularjs Directive_Owl Carousel - Fatal编程技术网

Angularjs 猫头鹰转盘不识别ng重复的元素

Angularjs 猫头鹰转盘不识别ng重复的元素,angularjs,angularjs-directive,owl-carousel,Angularjs,Angularjs Directive,Owl Carousel,我正试着去上班 在我看来,我希望这样标记,因为我有许多图库: <owl-carousel owl-options="owlOptions"> <div ng-repeat="image in gallery" class="item"> <p>hello</p> </div> </owl-carousel> 您想看看这些答案: 您想看看这些答案: 必须对您的指令进行一些更改,以便它能够在同一页面上处理多个旋

我正试着去上班

在我看来,我希望这样标记,因为我有许多图库:

<owl-carousel owl-options="owlOptions">
  <div ng-repeat="image in gallery" class="item">
    <p>hello</p>
  </div>
</owl-carousel>

您想看看这些答案:


您想看看这些答案:


必须对您的指令进行一些更改,以便它能够在同一页面上处理多个旋转木马。这里是一个链接到一个工作

这是HTML

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.transitions.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js" />
    <script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.15/angular.js" data-semver="1.3.15"></script>
    <script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <data-owl-carousel class="owl-carousel" data-options="{navigation: true, pagination: false, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items1" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
    <data-owl-carousel class="owl-carousel" data-options="{navigation: false, pagination: true, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items2" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
  </body>

</html>

必须对您的指令进行一些更改,以便它能够在同一页面上处理多个旋转木马。这里是一个链接到一个工作

这是HTML

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.transitions.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js" />
    <script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.15/angular.js" data-semver="1.3.15"></script>
    <script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <data-owl-carousel class="owl-carousel" data-options="{navigation: true, pagination: false, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items1" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
    <data-owl-carousel class="owl-carousel" data-options="{navigation: false, pagination: true, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items2" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
  </body>

</html>

您能描述一下使用ng repeat时实际发生的情况吗?对问题进行猜测是可以的,但是如果没有预期的和实际的结果,就无法验证。我得到了重复项目的列表,但是它们不会进入滑块。如果我只列出项目而不重复ng,那么它将初始化到滑块中。我认为ng repeat是在slider指令尝试初始化后运行的,但没有发现任何结果。您能描述一下使用ng repeat时实际发生的情况吗?对问题进行猜测是可以的,但是如果没有预期的和实际的结果,就无法验证。我得到了重复项目的列表,但是它们不会进入滑块。如果我只列出项目而不重复ng,那么它将初始化到滑块中。我认为ng repeat是在slider指令尝试初始化后运行的,但没有找到任何结果。@DTing,一个更正:您需要将link:函数移到owlCarousel指令的本地范围之外。@DTing,我只是在使用您的解决方案时,将每个项目添加到对象中,并由GET requestsone为每个项目重复,然后我推送它。问题在于作用域。$last在第一个作用域上是正确的,在所有其他作用域上也是正确的,当第二次调用它时,所有的项目都不会进入旋转木马。我能做什么?尝试了这个,我得到了TypeError:scope.initCarousel不是一个函数如何通过多个ng重复来实现?我必须在两个不同的数组中循环,一个是视频,一个是图像,我希望它们都在同一个旋转木马中。顺便说一句,您可以安全地删除指令上的transclude属性。这是假的default@DTing,一个更正:您需要将link:函数移到owlCarousel指令中的本地范围之外。@DTing,我使用您的解决方案时,每个项都被添加到对象中,并由GET requestsone为每个项重复,然后我推送它。问题在于作用域。$last在第一个作用域上是正确的,在所有其他作用域上也是正确的,当第二次调用它时,所有的项目都不会进入旋转木马。我能做什么?尝试了这个,我得到了TypeError:scope.initCarousel不是一个函数如何通过多个ng重复来实现?我必须在两个不同的数组中循环,一个是视频,一个是图像,我希望它们都在同一个旋转木马中。顺便说一句,您可以安全地删除指令上的transclude属性。这是假的,非常感谢!你救了我一周:非常感谢!你救了我一周:
var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.items1 = [1,2,3,4,5];
  $scope.items2 = [1,2,3,4,5,6,7,8,9,10];
}).directive("owlCarousel", function() {
    return {
        restrict: 'E',
        transclude: false,
        link: function (scope) {
            scope.initCarousel = function(element) {
              // provide any default options you want
                var defaultOptions = {
                };
                var customOptions = scope.$eval($(element).attr('data-options'));
                // combine the two options objects
                for(var key in customOptions) {
                    defaultOptions[key] = customOptions[key];
                }
                // init carousel
                $(element).owlCarousel(defaultOptions);
            };
        }
    };
})
.directive('owlCarouselItem', [function() {
    return {
        restrict: 'A',
        transclude: false,
        link: function(scope, element) {
          // wait for the last item in the ng-repeat then call init
            if(scope.$last) {
                scope.initCarousel(element.parent());
            }
        }
    };
}]);
<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.theme.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.transitions.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js" />
    <script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.15/angular.js" data-semver="1.3.15"></script>
    <script data-require="jquery@2.1.3" data-semver="2.1.3" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/owl-carousel/1.3.3/owl.carousel.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <data-owl-carousel class="owl-carousel" data-options="{navigation: true, pagination: false, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items1" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
    <data-owl-carousel class="owl-carousel" data-options="{navigation: false, pagination: true, rewindNav : false}">
      <div owl-carousel-item="" ng-repeat="item in ::items2" class="item">
        <p>{{::item}}</p>
      </div>
    </data-owl-carousel>
  </body>

</html>