Reactive form: how to manage correctly an array

19 views
Skip to first unread message

Andrea Mariotti

unread,
Sep 7, 2021, 8:36:00 AM9/7/21
to Angular and AngularJS discussion
Hello everyone,

I need to create an app where I've got a table with:
- Columns: day of selected month;
- Rows: firstname & lastname 

In this app the user can add rows, and in every row he has to write the working hours for each day.

The base data array is something like:
{
    "WorkingHoursCalendar": [
        {
            "name": "Paul",
            "days": [
                {
                    "date": "1/08/2021",
                    "hours": 0
                },
                {
                    "date": "2/08/2021",
                    "hours": 0
                },
                {
                    "date": "3/08/2021",
                    "hours": 0
                },
                {
                    "date": "4/08/2021",
                    "hours": 0
                },
                {
                    "date": "5/08/2021",
                    "hours": 0
                }
            ]
        },
        {
            "name": "Anne",
            "days": [
                {
                    "date": "1/08/2021",
                    "hours": 0
                },
                {
                    "date": "2/08/2021",
                    "hours": 8
                },
                {
                    "date": "3/08/2021",
                    "hours": 8
                },
                {
                    "date": "4/08/2021",
                    "hours": 8
                },
                {
                    "date": "5/08/2021",
                    "hours": 0
                }
            ]
        },
        {
            "name": "John",
            "days": [
                {
                    "date": "1/08/2021",
                    "hours": 8
                },
                {
                    "date": "2/08/2021",
                    "hours": 0
                },
                {
                    "date": "3/08/2021",
                    "hours": 0
                },
                {
                    "date": "4/08/2021",
                    "hours": 0
                },
                {
                    "date": "5/08/2021",
                    "hours": 0
                }
            ]
        }
    ]
}

My problem is that I don't understand how to transform the {date,hours} array in formComponent/formArray. 

I created a formArray that contains one formComponent foreach "name" in the array, but I really don't understand how to proceed after that.

Can someone help me?

Reply all
Reply to author
Forward
0 new messages