0

I have this code where i group array:

  let result = this.events.reduce( function(r,a){  r[a.item] = r[a.item] || [];
        r[a.item].push(a);
        return r;
      }, Array());
        //this.events.map((event)=>{ console.log(event,'e'); this.items[event.item] = event; console.log('itemssss',this.items)});
        this.items = result;
        console.log(this.items);

Result that i get is this : enter image description here

How can i iterate now this two arrays in html ?? Any suggestion?

So i want first to display that from first array and then to display data from second array ?

1 Answer 1

1

If you want to keep the arrays separated:

You can iterate two times over them. Firstly on the main array and on the different arrays it contains:

<ul>
    <li *ngFor="let item of items">
        <ul>
            <li *ngFor="let order of item">
                <!-- You can access objects properties here -->
                {{ order.statusName }} // <-- for example
            <li>
        </ul>
    <li>
</ul>

Other solution:

You can also merge them before looping on them :

So change this.items = result to this.items = this.items.concat(result);

After that, you can iterate over this.items. For example:

<ul>
    <li *ngFor="let item of items">
        ...
        {{ item.statusName }}
        ...
    </li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.