In this article I will explain with an example, how to display Images inside ng-repeat directive in AngularJS.
The ng-src directive is used along with Image elements in order to display Images from Model in AngularJS.
The Image will be stored in a Folder (Directory) on the Server and will be displayed by assigning the Path (URL) of the Image to the ng-src directive in AngularJS.
 
 
Display Images inside ng-repeat in AngularJS
The below HTML Markup consists of an HTML DIV to which ng-app and ng-controller AngularJS directives have been assigned.
The HTML DIV consists of an HTML Button and Table consisting of Image elements which will be populated from JSON array using ng-repeat directive.
Note: If you want to learn more about these directives please refer my article Introduction to AngularJS.
 
The Button has been assigned ng-click directive. When the Button is clicked, the GenerateTable function of the Controller gets called.
Note: If you want to learn more about ng-click directive, please refer my article ng-click directive example
 
Inside the GenerateTable function, an array of JSON objects is created and assigned to the Customers JSON array.
Each JSON object consists of the Customer Id, Name and Photo fields. The Photo field stores the URL of the Image.
The ng-repeat directive as the name suggests repeats the element based on the length of the collection, in this scenario it will repeat the TR element (HTML Table Row).
The TBODY element of the HTML Table has been assigned ng-repeat directive in order to iterate through all the items of the Customers JSON array.
For each JSON object in the Customers JSON array, a TR element (HTML Table Row) is generated and appended into the HTML Table.
The Photo field will be assigned to the ng-src directive which will read the Image URL from the Model and display the Image in the Image element.
<html>
<head>
    <title></title>
</head>
<body>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script>
    <script type="text/javascript">
        var app = angular.module('MyApp', [])
        app.controller('MyController', function ($scope) {
            $scope.IsVisible = false;
            $scope.GenerateTable = function () {
                $scope.Customers = [
                { CustomerId: 1, Name: "John Hammond", Photo: "Images/1.jpg" },
                { CustomerId: 2, Name: "Mudassar Khan", Photo: "Images/2.jpg" },
                { CustomerId: 3, Name: "Suzanne Mathews", Photo: "Images/3.jpg" },
                { CustomerId: 4, Name: "Robert Schidner", Photo: "Images/4.jpg" }
               ];
                $scope.IsVisible = true;
            };
        });
    </script>
    <div ng-app="MyApp" ng-controller="MyController">
        <input type="button" value="Generate Table" ng-click="GenerateTable()" />
        <hr />
        <table cellpadding="0" cellspacing="0" ng-show="IsVisible">
            <tr>
                <th>Customer Id</th>
                <th>Name</th>
                <th>Photo</th>
            </tr>
            <tbody ng-repeat="m in Customers">
                <tr>
                    <td>{{m.CustomerId}}</td>
                    <td>{{m.Name}}</td>
                    <td><img alt="{{m.Name}}" ng-src="{{m.Photo}}" style="height:100px;width:100px" /></td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>
 
 
Screenshot
AngularJS ng-repeat Image example: Display Images inside ng-repeat in AngularJS
 
 
Browser Compatibility

The above code has been tested in the following browsers.

Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.

 
 
Demo
 
 
Downloads