Ng-repeat only shows the last value

I'm new to Angular, and the ng-repeat method is my problem:

I am doing tests to find out what I want to achieve now: swipe the table table to display some content

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

here is my ad 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}}
+4
source share
2 answers

This is because your object elementis an array with only one jsonin it, upgrade elementto become:

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

And, of course, the same should be done for all of your objects.

+6
source

You need to close braces

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'}]
    }
];
+5

Source: https://habr.com/ru/post/1666518/


All Articles