0

you can see the full code here: https://mattlewis92.github.io/angular-calendar/#/async-events

I'm trying to make a Calendar in Angular and I'm using the module angular-calendar, it's filling me correctly the async events in my calendar, the problem is when I try to fill it up with events that not needs to be requested from the API:

export interface CalendarEvent {

    start: Date;
    end?: Date;
    title: string;
    color: EventColor;
    actions?: EventAction[];
    allDay?: boolean;
    cssClass?: string;
    resizable?: {
        beforeStart?: boolean;
        afterEnd?: boolean;
    };
    draggable?: boolean;

}

interface Film {

  id: number;
  title: string;
  release_date: string;

}

interface FilmEvent extends CalendarEvent {

  film: Film;

}

events$: Observable;

this.events$ = this.http

  .get('https://api.themoviedb.org/3/discover/movie', {search})
  .map(res => res.json())
  .map(({results}: {results: Film[]}) => {
    return results.map((film: Film) => {
      return {
        title: film.title,
        start: new Date(film.release_date),
        color: colors.yellow,
        film
      };
    });
  });

as you can see the calendar is filled automatically by the changes on the Observable array events$ when requesting info from the API:

but the problem is that I haven't being able to manipulate the events$ array to simply add me a static event into the array, something like this:

        title: "STATIC EVENT",
        start: new Date(),  ///TODAY
        color: colors.yellow,
        film

So far I have tried to use two http stream response like this, I saved some Statics events in JSON :

this.test3= this.http .get("adresssAPI1")

this.test4 = this.http .get("STATICSEVENTSINJSON")

and I have tried to merge them in just one stream to be processed as a single stream

this.test5 = Rx.Observable.combineLatest(this.test3 this.test4)

this.events$=

this.test5.map(({results}: {results: Film[]}) => {

    return results.map((film: Film) => {
      return {
        title: film.title,
        start: new Date(film.release_date),
        color: colors.yellow,
        film
      };
    });
  });

I would appreciate any ideas to get this done, I'm a noob and I don't really understand very well how to manipulate an Observable Array

Diego
  • 304
  • 4
  • 16
  • Rather than asking a new question each time, please edit your original question – eko May 25 '17 at 13:20
  • Possible duplicate of [Is there any way to concat http response arrays, in just one array in angular 2](https://stackoverflow.com/questions/44171819/is-there-any-way-to-concat-http-response-arrays-in-just-one-array-in-angular-2) – eko May 25 '17 at 13:20

1 Answers1

0

If you want to get data from 2 json files and merge the results then you can simply do the following:

var one$ = this.http.get('url for first json');
var two$ = this.http.get('url for second json');

this.events$ = Observable.forkJoin(one$, two$);

Run: https://jsfiddle.net/ibrahimislam/r7dojscr/1

If you want to provide inline data then you can do the following:

this.events$ = Observable.from([{ data: { id: 1 } }]);

lbrahim
  • 3,710
  • 12
  • 57
  • 95