Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 无法设置未定义的属性号_Angular - Fatal编程技术网

Angular 无法设置未定义的属性号

Angular 无法设置未定义的属性号,angular,Angular,我有一个组件,并试图分配给一个对象一些道具。试一试。我没有错误,但UI上没有显示任何内容,在try no 2中,我有一个错误“无法设置未定义的属性号” 您的数组从不填充任何条目。this.days.forEach将为数组中的每个项执行某些操作,但由于数组为空,我什么也不做 您应该先填充数组,然后在其上使用forEach。您的数组从不填充任何条目。this.days.forEach将为数组中的每个项执行某些操作,但由于数组为空,我什么也不做 您应该首先填充数组,然后在其上使用forEach。当您循

我有一个组件,并试图分配给一个对象一些道具。试一试。我没有错误,但UI上没有显示任何内容,在try no 2中,我有一个错误“无法设置未定义的属性号”


您的数组从不填充任何条目。this.days.forEach将为数组中的每个项执行某些操作,但由于数组为空,我什么也不做


您应该先填充数组,然后在其上使用forEach。

您的数组从不填充任何条目。this.days.forEach将为数组中的每个项执行某些操作,但由于数组为空,我什么也不做


您应该首先填充数组,然后在其上使用forEach。

当您循环此项时,需要将日期添加到天数组中。
numberOfDaysCurrentMonth

ngOnInit() {
  this.days = [];

  for (let i = 0; i < this.numberOfDaysCurrentMonth; i++) {
    let day = {
      number: i,
      weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
      name: ''
    }
    this.days.push(day);
  }
}
ngOnInit(){
this.days=[];
for(设i=0;i
您尝试使用
this.days.forEach
没有任何作用,因为它在days数组中的每个空对象上循环


类似地,
this.days[i]
实际上是未定义的,因为数组是空的。

当您循环使用
this.numberOfDaysCorrentMonth时,您需要将日期添加到days数组中。

ngOnInit() {
  this.days = [];

  for (let i = 0; i < this.numberOfDaysCurrentMonth; i++) {
    let day = {
      number: i,
      weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
      name: ''
    }
    this.days.push(day);
  }
}
ngOnInit(){
this.days=[];
for(设i=0;i
您尝试使用
this.days.forEach
没有任何作用,因为它在days数组中的每个空对象上循环


类似地,
this.days[i]
实际上是未定义的,因为数组是空的。

您在哪里向该数组添加数据。days?
this.days[i]
将始终是未定义的,因为days数组从未填充过。您在哪里向该数组添加数据。days?
this.days[i]
将始终是未定义的,因为days数组从未填充过。
ngOnInit() {
  this.days = [];

  for (let i = 0; i < this.numberOfDaysCurrentMonth; i++) {
    let day = {
      number: i,
      weekDay: new Date(this.currentYear, this.currentMonth - 1, i).getDay(),
      name: ''
    }
    this.days.push(day);
  }
}