在此示例中,我想从服务中获取所有预订数据并将它们推送到数组 CalendarEvent[]。但我收到了这个错误Uncaught Error: Unable to convert "undefined" into a date
。我认为我的服务有问题?
ng-calendar.component.ts:
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,
});
}
}
预订.service.ts:
export class BookingService {
constructor(private http: HttpClient) { }
getAllBookings() {
return this.http.get('/api/bookings/')
.pipe(map(response => response));
}
}
BookingResource.cs:
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<TimeSlotResource> TimeSlots { get; set; }
public BookingResource()
{
TimeSlots = new Collection<TimeSlotResource>();
}
}