0

I'm using Angular-Flexslider on my App and I need it to display images from a json object.

Angular-flexslider includes a directive flex-slider which acts like ng-repeat so this works

<flex-slider slide="s in mySlides">
    <li>
        <img ng-src="{{s}}">
    </li>
</flex-slider>

However I need it to get images from on object not an array, and this doesn't work.

<flex-slider slide="(key, s) in mySlidesObj">
    <li>
        <img ng-src="{{s.slide}}">
    </li>
</flex-slider>

Is there anyway I can get this to work?

The Controller just has data:

app.controller('BasicSliderCtrl', function($scope) {
    $scope.mySlides = [
        'http://images.mydomain.com/General-3-320x320.jpg',
        'http://images.mydomain.com/Jared-video-320x320.jpg'
    ];

    $scope.mySlidesObj = {
      "1001" : {
        "slide" : "http://images.mydomain.com/img1.jpg"
      },      
      "1002" : {
        "slide" : "http://images.mydomain.com/ig2.jpg"
      },          
      "1003" : {
        "slide" : "http://images.mydomain.com/img3.jpg"
      },          
      "1004" : {
        "slide" : "http://images.mydomain.com/ig4.jpg"
      },

    }
});   
2
  • What does your controller look like? Commented Mar 6, 2015 at 17:53
  • The controller just has data. I need to tie it to a database, but for the moment I'm just trying to figure out how to get this to work with on object, other than an array. I edited my post with a snippet of code. Commented Mar 6, 2015 at 19:10

1 Answer 1

0

Glancing at the source code it looks like iterating over objects isn't supported.

Your best option is probably to manually turn your object into an array.

For example:

$scope.mySlides = Object.keys($scope.mySlidesObj).map(function(slideObj) {
  return $scope.mySlidesObj[slideObj].slide;
});

Demo: http://plnkr.co/edit/fJ8IrPAt0cInvzD6fwdy?p=preview

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.