2

Im trying to use metafizzy's flickity framework to display content dynamically, using angulars ng-repeat.

But for some reason the items seem to get pushed out from the flickity-viewport when loaded onto the DOM. Anyone know why that happens and how to avoid it?

The gallery works fine When displaying static content inside it like this;

HTML : STATIC MARKUP EXAMPLE

<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>

..its When trying to populate the gallery with the help of angular's ng-repeat directive,that the gallery breaks.

HTML : MARKUP USING 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');
});

Link to flickity api : http://flickity.metafizzy.co/api.htm

DayWalker
  • 21
  • 3

0 Answers0