Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ng-repeated images appearing BEFORE flickity viewport. #91

Open
dbarrett24 opened this issue Sep 4, 2017 · 5 comments
Open

Ng-repeated images appearing BEFORE flickity viewport. #91

dbarrett24 opened this issue Sep 4, 2017 · 5 comments

Comments

@dbarrett24
Copy link

dbarrett24 commented Sep 4, 2017

I beleive I'm having a similar issue to the person in this StackOverflow link:

https://stackoverflow.com/questions/35107652/flickity-carousel-items-pushed-out-of-viewport-with-ng-repeat

I haven't found a solution.

I'm using a custom directive modal with a flickity carousel that will show videos/images.

Here is my site thus far:
dave-barrett.com

$scope.flickityOptions={
cellSelector: '.carousel-media-cell',
cellAlign: 'left',
pageDots: true,
// groupCells: 3,
adaptiveHeight: true,
imagesLoaded: true,
autoPlay: true,
contain: true
}

The array in the JSON looks like:
"files": [
"./images/videos/dayz-light-leaks.mp4",
"./images/screenshots/Basketbrawl.png",
"./images/screenshots/Basketbrawl-1.png",
"./images/screenshots/Basketbrawl-2.png",
"./images/screenshots/Basketbrawl3.png"
]

I get the images to load, but they appear outside of the flickity viewport.

@benjamincharity
Copy link
Owner

Hey @dbarrett24 is it possible that you fixed your issue? It seems that the items are nested correctly:

screen shot 2017-09-05 at 8 24 06 am

Are you still seeing a different result?

@dbarrett24
Copy link
Author

dbarrett24 commented Sep 5, 2017 via email

@benjamincharity
Copy link
Owner

benjamincharity commented Sep 5, 2017

Ahh I didn't go quite deep enough. I see the issue now.

I was trying to compare against my existing demo for remote data but Codepen seems to be enforcing https for all requests :/ I'll have to work on that later.

That being said.. it seems like a very possible reason is that Flickity is being instantiated before the ng-repeat is fully populated. I would try manually creating the Flickity slider using the service as I do in the demo linked above. Wrap the creation inside a setTimeout to make sure it happens after the ng-repeat.

Not ideal, but as I've pointed out in other issues, the underlying Flickity library wasn't really created for a model driven approach so hacks are what we are left with.

(I'll try to fix the demo this evening)

Let me know how it goes.

@dbarrett24
Copy link
Author

dbarrett24 commented Sep 14, 2017

Sorry for the trouble. I'm relatively new to development.

Could you guide me on using the setTimeout/$timeout in this situation, I was having some trouble interpreting your demo and translating it to use in my code.

Here is the code I'm working with:

<div  class="carousel-wrapper" id="team-slider" bc-flickity="{{flickityOptions}}">
      <div class="card" ng-repeat="teamData in teamData">
        <img ng-src="{{teamData.logo}}">
      </div>
</div>

Using a controller and service. Here is the portion of the Controller i think i'd need to work with:
This is my attempt: I'm not quite sure what I'm doing wrong.

mainService.getTeams().then(function (teamData) {

        $scope.teamData = teamData;
        console.log($scope.teamData)


        var element = angular.element(document.getElementById('team-slider'));
   
        $timeout(function () {

            // Initialize our Flickity instance
            FlickityService.create(element[0], element[0].id);
        });
    });

I feel like I'm close, but I'm getting an Error from Flickity saying: "This ID is already in use", referring to the ID "team-slider"

The repo to the project I'm currently working on is: https://github.com/dbarrett24/basketbrawwl-app

The files I've been working in:

./public/views/team-choicesCtrl.js
./public/views/team-choices.html


**Edit, I was able to get the desired visual (working carousel), but still receive the error: "This ID is already in use". Not sure why it's showing up. Thanks!

***EDIT AGAIN: Tried hosting the code I had temporarily, but noticed the carousel was broken again, the ng-repeated cells are showing up outside of the flickity viewport:

Here is the hosted version, Most source code available in the inspector: http://basketbrawwl.dave-barrett.com/#!/team-select

@benjamincharity
Copy link
Owner

With the code above, you are actually instantiating the flickity directive twice. The data attribute in the dom (bc-flickity) is trying to initialize a flickity slider using the ID of the element that it is on. Then the controller is trying to manually create another slider using that same ID which throws the error you are seeing.

I believe if you remove the bc-flickity attribute, it should work. You are still seeing the broken version because the $timeout is specifically making the service wait until after the DOM has finished, so the directive version of the slider wins.

You can pass your flickity options object to the service at creation: FlickityService.create(element[0], element[0].id, flickityOptions);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants