Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
Angularjs 在日历上从数据库加载事件_Angularjs_Arrays_Typescript_Calendar - Fatal编程技术网

Angularjs 在日历上从数据库加载事件

Angularjs 在日历上从数据库加载事件,angularjs,arrays,typescript,calendar,Angularjs,Arrays,Typescript,Calendar,我正在尝试从我的日历视图中的数据库加载事件。。我已经制作了api,可以返回我的资源,但是我没有成功地将它们绑定到CalendarEvents上。。这是我试图做到的部分 浏览器控制台显示“未定义”错误: 设法让它像这样工作,但它没有添加到数组中(好吧,它只是将它已经添加的数组切换为新的数组),我的意思是,我明白为什么,但努力修复它 我想知道我怎样才能推到它,或者在任何需要的情况下添加索引,以某种方式使它工作。。由于某些原因,直接推送到原始数组无法将数据保存到其中,因此我必须制作另一个数组,并在循环

我正在尝试从我的日历视图中的数据库加载事件。。我已经制作了api,可以返回我的资源,但是我没有成功地将它们绑定到CalendarEvents上。。这是我试图做到的部分

浏览器控制台显示“未定义”错误:

设法让它像这样工作,但它没有添加到数组中(好吧,它只是将它已经添加的数组切换为新的数组),我的意思是,我明白为什么,但努力修复它


我想知道我怎样才能推到它,或者在任何需要的情况下添加索引,以某种方式使它工作。。由于某些原因,直接推送到原始数组无法将数据保存到其中,因此我必须制作另一个数组,并在循环结束时将数据保存到原始数组中。。另外,为了使它不是“未定义的”,并允许我推到它,它必须在Begging时为“=[](等于empy数组)

  events: any;
  items: Array<CalendarEvent<{ time: any }>> = [];


this.eventsService.requestEvents().subscribe(res => {
  for(let i=0; i<res.data.length; i++) {
      this.items.push(
      {
        title: res.data[i].name,
        start: new Date(res.data[i].date),
        color: {primary: '#e3bc08', secondary: '#FDF1BA'},
        meta: {
          time: res.data[i].date
        }
    });
    this.events = this.items;
  }
});
事件:任何;
项目:数组=[];
this.eventsService.requestEvents().subscribe(res=>{

对于(设i=0;i,因为您的代码在屏幕截图中,所以我将用伪ish代码显示它。在订阅中,请执行以下操作:

this.events = [];
for (let i=0; i<res.data.length; i++) {
    this.events.push({
        title: res.data[i].name,
        start: res.data[i].date,
        color: { ... }
    });
}
this.events=[];

对于(让我=0;当你在这里复制代码时,我会让回答者更容易,而不仅仅是截图。nvm,修复了它。thx无论如何,请编辑你的问题,删除截图,并将其替换为纯格式文本的实际代码。解释了原因。给出了我最好的修复答案。但是没有旧代码来复制旧版本,我在那里不管怎么说,也没什么大不了的。。。