0

this is my object

enter image description here

I try to display the number of images in this array but i can't figure why this is not working and it makes me crazy !

  <ion-item ng-click="openModal(value.$id)" ng-repeat="value in items | orderBy: '-$id' track by $index "
               class="item item-avatar" style="text-align:left">

                   <img ng-if="value['image'].image" ng-src="data:image/jpeg;base64,{{value['image'].image}}">
                   <img ng-if="!value['image'].image" ng-src="img/shelter.png">
                   <h2>{{value.nom}} </h2>
                   <p>{{value.adresse}}</p>
                   <p>{{items[0].images.length  }} Photographie(s)</p>
          </ion-item>

How can i display the length of this "images" object please ? What is missing ?

EDIT : {"-KO5d2zxMY9wZd9Vp64s":true} Photographie(s) is displaying when i put
<p>{{value.images }} Photographie(s)</p>

Pablo DelaNoche
  • 677
  • 1
  • 9
  • 28

2 Answers2

1

Why not use

$scope.images_length = Object.keys(items[0].images).length;

function MyCtrl($scope) {
  $scope.items = {};
  $scope.items = [{"images": {"item1": "1", "item2": "2"}}];
  $scope.images_length = Object.keys($scope.items[0].images).length
}

And then in your view:

<div ng-app="">
  <div ng-controller="MyCtrl">
      {{images_length}}
  </div>
</div>

A Fiddle: http://fiddle.jshell.net/htt3x5Lc/

Thalaivar
  • 23,282
  • 5
  • 60
  • 71
0

Ok, so i figured it out !
I created an other filter in app.js

.filter('keylength', function(){
     return function(input){
     if(!angular.isObject(input)){
          return '0';
      }
     return Object.keys(input).length;
  }
})

and in my view :

<p>{{ value.images | keylength }} Photographie(s)</p>

And it's perfect :) Thank you very much for your help !

Pablo DelaNoche
  • 677
  • 1
  • 9
  • 28