Flickity carousel:使用ng-repeat从视口中推出的项目?

时间:2016-01-30 21:58:34

标签: angularjs mediawiki ng-repeat flickity

我试图使用metafizzy的flickity框架动态显示内容,使用angulars ng-repeat。

但由于某些原因,这些项目在加载到DOM时似乎会从flickity-viewport中推出。任何人都知道为什么会这样,以及如何避免它?

图库工作正常时在其中显示静态内容;

HTML:静态标记示例

<div ng-controller="FlickityCtrl">
   <div id="main-content" class="gallery js-gallery">
     <div class="gallery-cell"> Static Title </div>
     <div class="gallery-cell"> Static Title </div>
     <div class="gallery-cell"> Static Title </div>
  </div>

..当试图在angular的ng-repeat指令的帮助下填充画廊时,画廊会破坏。

HTML:使用NG-REPEAT进行标记

<div ng-controller="FlickityCtrl" >
  <div id="main-content" class="gallery js-gallery">
    <div ng-repeat="chapter in chapters" ng-click="loadSubchapters(chapter.title)">
    <h1  class="gallery-cell cell-card-bg"> 
        {{ chapter.title | strip_namespace }} 
   </h1>
</div>
  </div>
  <hr>
     <button ng-click="loadChapters()" >Load chapters</button>
  <hr>
  <ul>
    <li ng-repeat="chapter in subchapters">
      {{ chapter.title | strip_namespace }}
    </li>
  </ul><br />
   <hr >
 </div>

JAVASCRIPT

angular.module('FlickityApp', [])
   .controller('flickityCtrl', ['$scope', '$timeout', function ($scope, $timeout) {

var updateUI = function(data) {
    if (!data || !data.query) { return; }
    $timeout(function() {
        $scope.chapters = data.query.pages;
        console.log(data);
    });
};

$scope.loadChapters = function() {
    mw.loader.using('mediawiki.api', function() {
        (new mw.Api()).get({
            action: 'query',
            generator: 'categorymembers',
            gcmtitle: 'Category:examplepage'
        }).done(function(data) {
            $timeout(function() {
                $scope.chapters = data && data.query ? data.query.pages : {};

            });
        });
    });
};

$scope.loadSubchapters = function(chapterTitle) {
    mw.loader.using('mediawiki.api', function() {
        (new mw.Api()).get({
            action: 'query',
            generator: 'categorymembers',
            gcmtitle: chapterTitle
        }).done(function(data) {
            $timeout(function() {
                $scope.subchapters = data && data.query ? data.query.pages : {};
            });
        });
      });
   };
}])


.filter('strip_namespace', ['$sce', function($sce){
return function(text) {
    text = text.split(":");
    return text.length > 1 ? text[1] : text[0];
   };
 }]);
.directive('flickity', [function() {
   return {
      restrict: 'E',
      templateUrl: 'templates/view.html',
      replace: true,
      scope: { chapters: '=' },
      link: function(scope, elem, attrs, ctrl) {
         scope.$watch('chapters', function() {
        elem.flickity({
        // settings
           });
         });
      }
   };
}]);
angular.element(document).ready(function() {
    angular.bootstrap(document, ['FlickityApp']);
    var flkty = new Flickity('.gallery');
});

链接到flickity api http://flickity.metafizzy.co/api.htm

0 个答案:

没有答案