简体   繁体   中英

How to get first image from json response

How to get first image form the response from below response

["147038089457a43b5e47d2a_job1.jpg", "147038089457a43b5e48065_job2.jpg", "147038089457a43b5e4829c_jobo_3.jpg"]

I have tried ng-repeat is not working here.

What you have mentioned in your question is an array.

 ["147038089457a43b5e47d2a_job1.jpg",
 "147038089457a43b5e48065_job2.jpg",
 "147038089457a43b5e4829c_jobo_3.jpg"]

Assuming this value is assigned to say a variable x, getting the first image from this response should be as simple as reading the first value x[0] .

<img src="x[0]" />

in you controller you would have...

$scope.amitImages = ["147038089457a43b5e47d2a_job1.jpg",
"147038089457a43b5e48065_job2.jpg",
"147038089457a43b5e4829c_jobo_3.jpg"]

If you want to do a repeat: In your view (html) you would have..

<ul>
    <li ng-repeat="image in amitImages">
      <img ng-src="{{ image }}"/>
    </li>
  </ul>

If you JUST want the first image: In your view (html) you would have..

<img ng-src="{{ image[0] }}"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM