基本上我尝试做的是在数据库中创建一个假日,然后刷新日历,但是在假日更新之前刷新并且我的新日历没有显示,所以我怎么能等到put方法完成并且然后回复承诺?
这是我的方法
class CalendarService implements ICalendarService {
public static $inject = [
'$state',
'$q',
'Api',
'Orgs',
'User'
];
public org
constructor(private $state: IStateService, private $q: any, private Api: any, private Org: IOrgsService, private User: IUserService) {
var that: any = this
Org.getMyOrg().then(org => {
that.org = org
})
}
public createHoliday = (event: IEvent) => {
var that = this
this.org.put()
return that.$q.resolve({
id: maxid+1,
title: event.title,
calendar_type: "holdays",
start_date: event.startDate.toISOString().slice(0,10),
end_date: event.endDate.toISOString().slice(0,10),
description: event.description
})
}
public addEvent = (form: ng.IFormController) => {
var promise = this.Calendar.createHoliday(this.event)
promise.then((response: restangular.IResponse) => {
this.$uibModalInstance.close(response);
});
};
modalInstance.result.then((event: any) => {
this.uiCalendarConfig.calendars.currentCalendar.fullCalendar('refetchEvents');
});
因为createHoliday
是异步执行的,它不等待this.org.put()
执行then()
的响应,所以它什么也没有返回......