Question: I have two jsons: templates, and images

```
$scope.templates = [
        {"id_template": 1, "name": "First Template", "group": "sport"}
        {"id_template": 2, "name": "Second Template", "group": "animals"},
        ];

    $scope.images = [
        {"id_image": 1, "id_template": 1, "title":"Image Lewy"},
        {"id_image": 2, "id_template": 1, "title":"Image ball"},
        {"id_image": 3, "id_template": 2, "title":"Image dog"},
    ]

```

I would like to display in the view images sorted by id\_template. I know that you must create a loop in the loop but do not know how ?
My view.html: 

```
<div class="images" ng-repeat="template in templates">
 {{template: name}}
 Images to this template: 
 <ul>
  <li ng-repeat="image in images | filter:template.id_template">{{image.title}}</li>
</ul>
</div>

```

Answer: 
You can sort in angular by using orderBy filter. Please go through <https://docs.angularjs.org/api/ng/filter/orderBy> documentation if you want more details. From example below the result will be ascending and if you want it to be descending order add '-template\_id'

**Ascending**

```
<div class="images" ng-repeat="template in templates | orderBy: 'template_id'">
 {{template.name}}
 Images to this template: 
 <ul>
  <li ng-repeat="image in images | filter:{id_template:template.id_template}">{{image.title}}</li>
</ul>
</div>

```

**Descending**

```
<div class="images" ng-repeat="template in templates | orderBy: '-template_id'">
 {{template.name}}
 Images to this template: 
 <ul>
  <li ng-repeat="image in images | filter:{id_template:template.id_template}">{{image.title}}</li>
</ul>
</div>

```
you must use OrderBy for sorting items in angularjs

```
<li ng-repeat="image in images | orderBy:template.id_template">{{image.title}}</li>

```