Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/465.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
Javascript ng fullcalendar只需以角度显示具有特定id的事件_Javascript_Angular_Fullcalendar - Fatal编程技术网

Javascript ng fullcalendar只需以角度显示具有特定id的事件

Javascript ng fullcalendar只需以角度显示具有特定id的事件,javascript,angular,fullcalendar,Javascript,Angular,Fullcalendar,我正在尝试使用ng fullcalendar为我的angular应用程序创建scheluder。我安装它没有任何问题,但我只想从我的event.service呈现一些特定的ID。这是我的NgOnInit: ngOnInit() { this.eventService.getEvents().subscribe(data => { console.log(data[0].id); this.calendarOptions = { ed

我正在尝试使用ng fullcalendar为我的angular应用程序创建scheluder。我安装它没有任何问题,但我只想从我的event.service呈现一些特定的ID。这是我的NgOnInit:

 ngOnInit() {
     this.eventService.getEvents().subscribe(data => {
       console.log(data[0].id);
       this.calendarOptions = {
         editable: true,
         eventLimit: false,
         header: {
           left: 'prev,next today',
           center: 'title',
           right: 'agendaWeek,agendaDay'
         },
         defaultView: 'agendaWeek',
         events: data,
       };
     });
   }
我的events.service看起来像:

import { Inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
@Injectable()
export class EventService {
    public getEvents(): Observable<any> {
        const dateObj = new Date();
        const yearMonth = dateObj.getUTCFullYear() + '-' + (dateObj.getUTCMonth() + 1);
        let data: any = [{
            id: 999,
            title: 'All Day Event',
            start: yearMonth + '-01'
        },
        {
            id: 998,
            title: 'Long Event',
            start: yearMonth + '-07',
            end: yearMonth + '-10'
        },
        {
            id: 999,
            title: 'Repeating Event',
            start: yearMonth + '-09T16:00:00'
        },
        {
            id: 998,
            title: 'Repeating Event',
            start: yearMonth + '-16T16:00:00'
        }
       ];
        return Observable.of(data);
    }
};
在目前的情况下,我认为所有这些事件都会发生。例如,我需要对此代码进行哪些更改以仅显示id为“999”的事件

感谢那些花时间帮助我的人

您可以使用以下方法进行筛选: data.filter ev=>ev.id='999'

所以在你的ngOnInit上会变成这样:

ngOnInit() {
 this.eventService.getEvents().subscribe(data => {
   console.log(data[0].id);
   this.calendarOptions = {
     editable: true,
     eventLimit: false,
     header: {
       left: 'prev,next today',
       center: 'title',
       right: 'agendaWeek,agendaDay'
     },
     defaultView: 'agendaWeek',
     events: data.filter( ev => ev.id == '999'),
   };
 });
   }
您也可以从事件的空列表开始,然后使用方法插入它们

this._calendar.fullCalendar('renderEvents', #your Filtered events#, true);

谢谢你的帮助!它直接工作,你的第二个选择!