2

I am using angular 5. I am trying to use the following array in nested ngFor loops in html

Object:

    [
    {
        "copyFromDay": "Sunday",
        "days": [
           "Monday",
           "Tuesday",
           "Wednesday",
           "Thursday",
           "Friday",
           "Saturday"
        ]
    },
    {
        "copyFromDay": "Monday",
        "days": [
            "Sunday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
            "Saturday"
        ]
    }//,....   
]

HTML:

<table>
        ....
    <tr>
        <td *ngFor="let sourceDay of copyToArray">
            <label>sourceDay.copyFromDay</label>
                <ul><li *ngFor="let day of sourceDay.days">
                <label><input type="checkbox" />{{day}}</label>
                </li></ul>
        </td>
    </tr>
<table>

I am getting the following parsing error:

Can't bind to 'ngforOf' since it isn't a known property of 'li'. enter image description here

I have imported BrowserModule and CommonModule in the app.module.ts I am doing this so that the user can copy a schedule from any day of the week to the rest of the week.

EDIT: Actual HTML from my code:

<td *ngFor = "let sourceDay of copyFromArray">
    <div class="copytodiv">
        <div class="dropdown">
            <button type="button" class="btn btn-default btn-raised copytobtn dropdown-toggle" data-toggle="dropdown">Copy to <i class="fa fa-chevron-down" aria-hidden="true"></i></button>
            <ul class="dropdown-menu">
                <li *ngfor="let day of sourceDay.days">
                    <div class="checkbox">
                        <label>
                            <input type="checkbox"> {{day}}
                        </label>
                    </div>                                                        
                </li>
            </ul>
        </div>
    </div>
</td>
Kaushik
  • 123
  • 13
  • I can modify the array to more optimal structure for achieving this task. Please let me know if anything is wrong with it's structure. – Kaushik May 03 '18 at 23:44
  • Check this and also make sure your key names are correctly used https://stackoverflow.com/a/40331563/1339516 – Searching May 03 '18 at 23:52
  • try `
  • ` and see if that works.. Im not sure you can do `sourceDay.day` in an `*ngFor`
  • – Smokey Dawson May 04 '18 at 00:02
  • @JuvenileSnow, We can do `sourceDay.days` as shown in the demo by Ashish Ranjan. – Kaushik May 04 '18 at 01:01