Angular-calendar: Example for dynamic loading for events

Created on 25 Dec 2016  路  7Comments  路  Source: mattlewis92/angular-calendar

Great library!
The examples given are static events. Is there an example of loading events from server, e.g, using firebase?

All 7 comments

The best way would be to make use of observables and the async pipe.

Based off the angular fire readme: https://github.com/angular/angularfire2

this.events$ = af.database.list('/events').map(event => {
  // add any extra event metadata here, rename properties to the format the calendar expects etc
  return event;
});

and then in your template:

[events]="events$ | async"

Hope that helps!

I am getting this error when passing events asynchronously (like in your example): "Cannot read property 'filter' of null at getEventsInPeriod". When I debugged I noticed that ngOnChanges of the lib was triggered and events value was null so that caused the error. So I guess null value of events is passed before real data comes.

This workaround works: [events]="(events | async) || []"

I'm a noob in AngularFire2. How do you setup -> events: CalendarEvent[] with FirebaseListObservable

I guess you should declare your variable as events$: FirebaseListObservable<CalendarEvent[]> and then assign af database observable to it as in the @mattlewis92 example. In map function you transform from your definition to CalendarEvent:

        this.events$ = af.database.list('/events').map(events => {
            return events.map(e => {
                return {
                    title: e.name,
                    start: e.date,
                    color: colors.red
                };
            });
        });

Hi, I was trying to use this async thing, but faced some problem here, any chance you guys can help:
http://stackoverflow.com/questions/41787442/angular2-split-elements-in-observable-to-fit-async-pipe

Much appreciated

Hi. Thanks to all the previous comments, I managed to get it working like this. In your ts file:

export class HomePage {
events: FirebaseListObservable

constructor (public af: AngularFire) {
this.events = af.database.list('/events').map( events => {
return events.map( e => {
return {
title: e.name,
start: e.start,
color: colors.red
}
})
}) as FirebaseListObservable }
}

In your html file:
[events]="(events | async) || []">

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vinay13 picture vinay13  路  3Comments

oldschoolbg picture oldschoolbg  路  4Comments

Novabllast picture Novabllast  路  3Comments

fmoessle picture fmoessle  路  5Comments

PrasannaKolla picture PrasannaKolla  路  4Comments