1

html:- i have used ng-repeat to get all images.what should i add to get only single image.

<img class="size" ng-src="{{image.image}}" />

css:- i want to specify the size of image.

.size
{
margin-left:0.3em;
width:11em;
height:11em;
border:0.4em solid #B90504;
}

js:- i have used this code to pull all images from json. how can i get all the details of one image in one view and second image in another view??? where do i have to made changes??Do i need to specify the index number?

$http.get('data/flatfile.json')
.success(function(data, status, headers, config) {
    $scope.images = data.items;
});

json:-

{ 
 "items":[
           {

                "name": "chocolate",
                "price": 12.99,
                "description": ["string","string"],
                "category": "cakes",
                "image": "../img/product1.JPG"
           },

           {

                "name": "chocolate",
                "price": 12.99,
                "description": ["string","string"],
                "category": "cakes",
                "image": "../img/product2.JPG"
           },

           {

                "name": "chocolate",
                "price": 12.99,
                "description": ["string","string"],
                "category": "cakes",
                "image": "../img/product3.JPG"
           }
        ]
    }
6
  • can you share the whole code block where you have the ng-repeat directive? Commented Jul 9, 2015 at 17:46
  • <img class="size" ng-repeat="image in images" ng-src="{{image.image}}" ng-hide="image+1 in image" /> Commented Jul 9, 2015 at 18:21
  • you should expend your answer with the code in the OP, instead of pasting it as a comment, as it has not styling. Anyway, why are you using the ng-repeat directive, if you just want to show one image at a time? Is that correct, or have I misinterpreted how the page should behave? Commented Jul 9, 2015 at 18:28
  • its already written i have used ng-repeat for pulling all images.now i want only one image on one view.i am not using ng-repeat fo one image....check the above code. Commented Jul 9, 2015 at 18:55
  • sorry, you've shared 2 lines of html code, that's why it's unclear to me how the page should look like. If you want to pull all images, but display only one at a time, then you don't strictly need to use the ng-repeat directive. You can bind an img html element with a model (such as $scope.image) by using ng-model. Commented Jul 9, 2015 at 19:08

2 Answers 2

0

In your controller, use $scope.index=0;

in view load images using

<img class="size" ng-src="{{items[index].image}}" /> 

for next image to load in the same view put a next button and change the index in click function

<button ng-click="next()" >Load Next Image </button>
      $scope.next = function(){
            $scope.index=$scope.index+1;
        }
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for answer but its not working no image is showing on view...i dnot think specifying index number is working
0

Following up on the comments above, check this SO post where this problem was solved.

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.