我想知道在点击我制作的addEvent函数后如何立即反映数据。我试着调用我在构造函数中创建的getEvents,但除非我刷新页面
,否则它不会立即反映出来更新:
event.service.ts
public deleteEvent(id): Observable<any> {
const headers = new Headers({
'Content-Type': 'application/json'
});
const url = `${this.baseUrl}api/deleteevent/${id}`;
return this.http.delete(url)
.map((response: Response) => {
console.log(response.json().data);
return response.json();
})
.catch(err => {
return Observable.throw(err);
});
}
视图-calendar.ts
deleteEvent() {
this.eventService.deleteEvent(this.id).subscribe(
delData => {
this.delete = delData;
this.ucCalendar.fullCalendar('renderEvent', this.delete);
this.ucCalendar.fullCalendar('renderEvents');
}
);
}
getAllEvents() {
// store token in variable
const data = localStorage.getItem('token');
// decode the token
const decoded = jwt.decode(data);
// store data in user
this.user = decoded.data;
this.eventService.getEvents(this.user.faculty_number).subscribe(
eventData => {
this.eventData = eventData;
this.calendarOptions = {
editable: true,
eventLimit: false,
selectable: true,
header: {
left: 'prev,next today add',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
events: eventData
};
});
}