Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ng-repeat is only showing the last value

I'm new to Angular and method ng-repeat here is my issue:

I'm making tests to learn, here is what I want to achieve now: loop through a table of table to display some content

My issue is: second ng-repeat only shows the last value.

here is my declaration in the controller:

app.controller("ClientCtrl", function($scope){
$scope.ClientSections = [
    {title: 'Titre 1', element: 
        [{name: 'Toto', name: 'Contenu 1', name: 'Contenu 2', name: 'Contenu 3'}]
    },
    {title: 'Titre 2', element: 
        [{name: 'Titi', name: 'Contenu 2'}]
    },
    {title: 'Titre 3', element: 
        [{name: 'Titre 1', name: 'Contenu 3'}]
    }
];
});

here is my pug template

element(ng-repeat="ClientSection in ClientSections")
    h2 {{ClientSection.title}}
        item(ng-repeat="Client in ClientSection.element")
            p {{Client.name}}
like image 588
Sunkhern Avatar asked Dec 19 '22 10:12

Sunkhern


1 Answers

That is because your element object is an array with only one json in it, update your element to become:

element: 
    [{name: 'Toto'}, {name: 'Contenu 1'}, {name: 'Contenu 2'}, {name: 'Contenu 3'}]

And of course the same must be done to all of your objects.

like image 110
Tha'er M. Al-Ajlouni Avatar answered Dec 20 '22 22:12

Tha'er M. Al-Ajlouni