title: Uncaught Error: Unable to convert "undefined" into a date (Angular)
body: <p>In this example, I want to get all bookings data from a service and push them to an array CalendarEvent[]. But I received this error <code>Uncaught Error: Unable to convert "undefined" into a date</code>. I assumed that something is wrong with my service?</p>
  
  <p>ng-calendar.component.ts:</p>
  
  <pre><code>export class NgCalendarComponent {
    events: CalendarEvent[] = [];
    bookings: any = {};
    date: string;
  
    constructor(private bookingService: BookingService) {}
  
    ngOnInit() {
      this.bookings = this.bookingService.getAllBookings();
  
      for (let booking of this.bookings) {
        var b = this.bookings[booking];
        this.date = formatDate(b.bookDate, 'medium', 'en-us', 'GMT+8');
  
        this.events.push({
          start: new Date(this.date),
          title: b.purpose,
        });
      }
    }
  </code></pre>
  
  <p>booking.service.ts:</p>
  
  <pre><code>export class BookingService {
    constructor(private http: HttpClient) { }
  
    getAllBookings() {
      return this.http.get('/api/bookings/')
        .pipe(map(response =&gt; response));
    }
  }
  </code></pre>
  
  <p>BookingResource.cs:</p>
  
  <pre><code>public class BookingResource
  {
      public int Id { get; set; }
      public RoomResource Room { get; set; }
      public KeyValuePairResource Building { get; set; }
      public DateTime BookDate { get; set; }
      public ContactResource Contact { get; set; }
      public string Purpose { get; set; }
      public ICollection&lt;TimeSlotResource&gt; TimeSlots { get; set; }
  
      public BookingResource()
      {
          TimeSlots = new Collection&lt;TimeSlotResource&gt;();
      }
  }
  </code></pre>