Angular2 Count items inside of the array display information

rodboc picture rodboc · May 24, 2016 · Viewed 14.7k times · Source

Here again, I have the following component MyStoreComponent

 export class MyStoreComponent {
    stores: any[] = [{
        storeId: "456392",
        location: "New York",
        people: [{
            manager: "John",
            sales: "Claudia",
            tech: "Marcel"
        }, {
            manager: "Martin",
            sales: "Jenn",
            tech: "Oliver"
        }]
        }, {
        storeId: "456393",
        location: "California",
        people: [{
            manager: "Kim",
            sales: "Nancy",
            tech: "Marie"
        }]
    }];

 }

Now I am looking to count the people inside of each branch. For example 456392 has two manager or 456393 just have one

I tried myself with

 <ul *ngFor="#store of stores">
    <li *ngFor="#person of store.people">
        <span *ngIf="person.length > 1">Show this</span>
    </li>
 </ul>

But I am losing in some point, any help? please?

Answer

inoabrian picture inoabrian · May 24, 2016

Like awiseman mentioned it should be

<ul *ngFor="#store of stores">
    <li *ngFor="#person of store.people">
        <span *ngIf="store.people.length > 1">Show this</span>
    </li>
 </ul>