ngModel无法正常工作,FillTeachersChangesComponent.html:23错误TypeError:无法读取未定义的属性“ 0”

时间:2019-11-07 09:44:00

标签: html angular

我正在用angular6开发表格,试图制作可编辑的表格, 并且需要使用[(ngModel)]知道用户输入了什么,然后将其导出到Excel工作表...

问题是他写了我无法读取未定义的属性“ 0”, 虽然我定义了数组... 并且也没有显示第二个* ngfor,如我在所附图片中所示 here you can see 这是我的HTML: ........................... ...                                                                                                                    {{days [i + 1]}}                            

        <tr *ngFor=" let item of days;index as i">
          <td>
            <span>שם המורה</span><br />
            <input list="teachers" placeholder="הכנס שם" [(ngModel)]="subTeacherChanges.subbedTeacher[i]" name="a" />
          </td>

          <datalist id="teachers">
            <option *ngFor=" let item of teachersList; index as w " value="{{teachersList[w].name}}">
          </datalist>

          <td>
            <span>מילאה מקום המורה </span> <br />
            <input list="subTeachers" placeholder="הכנס שם" [(ngModel)]="subTeacherChanges.subTeacherName[i]"
              name="aa" />
          </td>

          <datalist id="subTeachers">
            <option *ngFor=" let item of subTeachersList; index as q" value="{{subTeachersList[q].name}}">
          </datalist>
          <td>
            <button> לחצי לצפיה בסך כל השעות שדווחו על המורה </button>
          </td>
          <td>
            <span>א-ו</span><br />
            <span>ו-ח</span>
          </td>

          <small>
            <td style="width:5px" *ngFor=" let item of days;index as h">
              <input style="width: 15px" [(ngModel)]="subTeacherChanges.hoursSubbed1[i][h]" name="aaa" />
              <input style="width: 15px" [(ngModel)]="subTeacherChanges.hoursSubbed2[i][h]" name="aaaa" />
            </td>
          </small>

        </tr>

      </table>
    </div>
  </div>
</div>

这是ts:

   ...
export class FillTeachersChangesComponent implements OnInit {

  papa: Papa;
  days: number[] = [];
  days1: number[] = [];


  constructor(private httpClient: HttpClient) {

  }


  //days:number=new Array[31];
  //teachersList:TeacherModel[]=[];
  teacherChanges: TeacherChangesModel[] = [];
  subTeacherChanges: SubTeachersChangesModel[] = [];


  teachersList: Array<TeacherModel> = [
    { id: 0, id1: '0', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
    { id: 1, id1: '0', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
    { id: 2, id1: '0 ', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
    { id: 3, id1: '0', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
    { id: 4, id1: '0', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
    { id: 5, id1: '0', name: 'הכנס שם', lastName: 'הכנס משפחה', nikName: 'הכנס כינוי', Sunday: 0, Monday: 0, Tuesday: 0, Wednesday: 0, Thursday: 0, Friday: 0, Sunday1: 0, Monday1: 0, Tuesday1: 0, Wednesday1: 0, Thursday1: 0, Friday1: 0 },
  ];

....

  ngOnInit() {
    for (let index = 0; index < 32; index++) {
      this.days.push(index);
      this.days1.push(index);

    }
      for (let index = 0; index < 100; index++) {
        this.subTeacherChanges.push(new SubTeachersChangesModel);
        this.teacherChanges.push(new TeacherChangesModel);

      }
    }

  }

0 个答案:

没有答案