Problem accessing the elements of an ng-repeat array

0

That such a community as you will see I am new to angularJs and I have a problem accessing the elements of an array.

here I have my controller

var app = angular.module("teApp")
.controller("NewPromotionDetailController", ['$window','$scope','$attrs','$http','$cookies', function($window, $scope, $attrs, $http, $cookies) {  
    var url = CQ.HTTP.noCaching(CQ.WCM.getDesign().getPath()+'/jcr:content/global.infinity.json');
    var items = CQ.HTTP.eval(url);
    $scope.sharedArray = items.compartirList;
    console.log(items.compartirList);
}]);

and the part of the HTML is where it fails to try to access an element of the array.

<div ng-controller="NewPromotionDetailController">
   <div ng-repeat="item in sharedArray">
          <p>{{item}}</p>
          <a href=""><img ng-src="{{item.iconoCompartir}}"/></a>
   </div>
</div>

As if I access it as such only {{item}} does it well brings with it each element within the array but if I try to access a particular data within each element it does not bring me anything, that is {{item.foo}} I already assured that this data does exist in the arrangement.

In this way comes the variable items.compartirList which is what I have in the scope so there is no problem with it

[{"iconoCompartir":"/content/dam/tecom/iconos/icon-fb.png","tipoCompartir":"external","enlaceCompartir":"https://www.facebook.com/","noFollowCompartir":["true"]},  
{"iconoCompartir":"/content/dam/tecom/iconos/icon-tw.png","tipoCompartir":"internal","enlaceCompartir":"https://twitter.com/login?lang=es","noFollowCompartir":[]}]
    
asked by Polo 02.01.2018 в 20:10
source

1 answer

0

Well back after a week since I had been very busy and could not answer before.

The problem seems to be that angular does not recognize the structure of the jsonArray so it can not access its elements, as the problem had to be resolved quickly choose to save the elements in an array and then pass that array in this way the ng-repeat would no longer be trying to read a jsonData if not an Array directly

            var app = angular.module("teApp")
        .controller("NewPromotionDetailController", ['$window','$scope','$attrs','$http','$cookies', function($window, $scope, $attrs, $http, $cookies) {
               var array = [];
               var url = CQ.HTTP.noCaching(CQ.WCM.getDesign().getPath()+'/jcr:content/global.infinity.json');
               var items = CQ.HTTP.eval(url);
               var jsonData = items;
               for(var i=0; i < jsonData.compartirList.length; i++ ){
                 array.push(JSON.parse(jsonData.compartirList[i]))
               }
               $scope.sharedArray = array;

        }]);

It's kind of weird because the structure of the json complies with the standard and in fact I could access its data with a simple for.

As I mentioned, I am a bit burdened with work so I could not join much in the matter if any of you can contribute something more to the problem I will thank you

    
answered by 10.01.2018 в 02:15