0

I'm developing a page where I need to show some boxes (using ng-repeat) that contains info of channels and where it will be shown(which cities).

The problem I am facing is when I repeat the second ng-repeat:

<table class="table table-condensed" ng-init="nitsCh = [objsCh[$index].nit]">

This should get the $index of first ng-repeat and create a new array with the places the channels will be shown. And it does exactly that. But, when I apply the second ng-repeat using this array, it doesn't works properly.

Said that, my html looks like this:

    <<div class="box box-solid box-default" ng-repeat="(indexO, objCh) in objsCh track by indexO" ng-if="indexO%4==0  && indexO<=10"> 
      <div class="box-header"> 
        <div class="pull-left"> 
          <img src="dist/img/channels/{{ objsCh[indexO].pic }}" data-toggle="tooltip" title="" data-original-title="Alterar logo do canal"> 
          <h3 class="box-title">{{ objsCh[(indexO)].name }}</h3> 
        </div> 
        <div class="box-tools pull-right"> 
          <button class="btn btn-box-tool" data-toggle="tooltip" title="" data-original-title="Adicionar ou Remover NIT"><i class="fa fa-plus"></i></button> 
        </div> 
      </div> 
      <div class="box-body"> 
        <table class="table table-condensed" ng-init="nitsCh = [objsCh[indexO].nit]"> 
          <tbody> 
            <tr> 
              <th style="width: 10px">#</th> 
              <th>Nit</th> 
            </tr> 
            <tr ng-repeat="(indexN,nitCh) in nitsCh track by indexN"> 
              <td>{{ objsCh[(indexO + 1)].nit[indexN].num }}</td>
              <td>{{ objsCh[(indexO + 1)].nit[indexN].name }}</td>
            </tr> 
          </tbody>
        </table> 
      </div> 
    </div>

The JS file looks like this:

var app = angular.module('appApp', []);

app.controller('ctrlApp', function($scope,$http) {

var url="includes/exibChNit.php";

$http.get(url).success( function(response) {
    all = response;
    $scope.objsCh = all.channels;
}); 

});

And the json file (that php create) looks like this:

{
"channels": [
    {
        "id": "1",
        "sid": "1",
        "name": "Channel",
        "pic": "channel.jpg",
        "crc32": "A1g423423B2",
        "special": "0",
        "url": "",
        "key": "",
        "type": "",
        "city": [
            {
                "num": "1",
                "name": "S�o Paulo"
            },
            {
                "num": "2",
                "name": "Rio de Janeiro"
            }
        ]
    },
    {
        "id": "2",
        "sid": "2",
        "name": "CHannel 1",
        "pic": "channel.jpg",
        "crc32": "A1F5534234B2",
        "special": "0",
        "url": "",
        "key": "",
        "type": "",
        "city": [
            {
                "num": "1",
                "name": "S�o Paulo"
            },
            {
                "num": "2",
                "name": "Rio de Janeiro"
            }
        ]
    }
]

}

Thanks in advance!

Best regards,

Bruno Ornelas
  • 331
  • 1
  • 3
  • 14
  • 1
    you don't need to use index for most of this anyway....use the objects themselves ...`{{ objsCh[($index)].name }}` == `{{objCh.name }}` – charlietfl Jul 17 '15 at 13:58
  • @charlietfl That's totally true. Btw I just added a new answer to the original post that looks pretty clear. http://stackoverflow.com/a/31477492/2516560 you can now use "ng-repeat = (key,value) in data" – Okazari Jul 17 '15 at 13:59
  • I need, because I am dividing it in four columns. Then I do objsCh[($index)].name for first column, objsCh[($index+1)].name for second, objsCh[($index+2)].name for third and objsCh[($index+3)].name for fourth – Bruno Ornelas Jul 17 '15 at 20:18

0 Answers0