0

I am trying to display the images from a json file. The urls of those images are stored in the json file. Right now given my code, it is just printing out the urls, which it should be, but I am wondering how I can display the actual image on browser instead of the path. The line of code to look at is this <td>{{article.cover_image_path}} </td>

Here is my html :

<html ng-app="myApp">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js"></script>
    <script>
      var myApp = angular.module('myApp', []);
      myApp.controller('myCtrl', function ($scope, $http){
        $http.get('articles.json').success(function(data) {
          $scope.articles= data;
        });
      });
    </script>
  </head>
  <body ng-controller="myCtrl">
    <table>
      <tr>
      <tr ng-repeat="article in articles">
        <td>{{article.title}}</td>
            <td>{{article.source}}</td>
        <td>{{article.publish_time}}</td>
        <td>{{article.cover_image_path}} </td>
      </tr>
    </table>
  </body>
</html>

my json file looks like this: enter image description here

3
  • try <img ng-src="{{article.cover_image_path}}" /> Commented Apr 5, 2017 at 0:37
  • If my answer satisfies your question, please accept it :) Commented Apr 5, 2017 at 0:51
  • See AngularJS ng-src API Reference. Commented Apr 5, 2017 at 0:57

1 Answer 1

1

By adding an img tag with the ng-src directive with the value of your image_path

<td><img ng-src="{{article.cover_image_path}}" alt="Description" ></td>
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.