2017-09-12 46 views
0

我試圖使用devextreme調度程序預約調度程序的應用程序。 我有一個小錯誤。我想知道爲什麼,當我創建約會和拖放任命我剛纔創建我有我的控制檯上的錯誤:devextreme調度程序的插件刷新錯誤 - 角4

PUT http://localhost/v0/croissant/undefined 404 (Not Found) 
appointment.service.ts:19 An error occurred Response {_body: "", status: 404, ok: false, statusText: "Not Found", headers: Headers…} 
webpackJsonp.../../../../../src/app/services/appointment.service.ts.AppointmentService.handleError @ appointment.service.ts:19 
ZoneDelegate.invoke @ zone.js:203 
onInvoke @ core.es5.js:3890 
ZoneDelegate.invoke @ zone.js:202 
Zone.run @ zone.js:96 
(anonymous) @ zone.js:462 
ZoneDelegate.invokeTask @ zone.js:236 
onInvokeTask @ core.es5.js:3881 
ZoneDelegate.invokeTask @ zone.js:235 
Zone.runTask @ zone.js:136 
drainMicroTaskQueue @ zone.js:368 
ZoneTask.invoke @ zone.js:308 
core.es5.js:1020 ERROR Error: Uncaught (in promise): Response with status: 404 Not Found for URL: http://localhost/v0/croissant/undefined 

但是當我刷新頁面,然後我移動的任命,一切工精細...

這裏是我的任命更新的方法我appointment.Service.ts

updateAppointment(id: string, userId :string, timestamp :string, reason: string): Promise<Appointment>{ 

    let bodySearchParam = new URLSearchParams(); 
    bodySearchParam.append('userId', userId); 
    bodySearchParam.append('timestamp', this.datetotimestamp(timestamp).toString()); 
    bodySearchParam.append('reason', reason); 
    let body = bodySearchParam.toString(); 


    var AppointmentUrlUpdate = this.AppointmentUrlWrite + "/" + id; 

    return this.http.put(AppointmentUrlUpdate, body) 
        .toPromise() 
        .then(response => 
         console.log("event updated") 
        ) 
        .catch(this.handleError); 

    } 

這裏是我的事件處理程序上我的日曆組件

updateAppointment(e: any){ 
    e.appointmentData.endDate = this.add30mnTo(e.appointmentData.startDate); // bugFix pour l'affichage du calendrier 
    this.appointmentService.updateAppointment(e.appointmentData.id, e.appointmentData.ownerId, e.appointmentData.startDate, e.appointmentData.text) 
    } 

這裏是我打電話給我的事件處理在我calendar.component.html

<dx-scheduler 
    (onAppointmentUpdated)= "updateAppointment($event)" 
> 

</dx-scheduler> 

感謝的對你有所幫助!

回答

0

問題是,我的API需要和ID來更新約會。但是ID現在不存儲。該決議的方法是:

createAppointment(userId :string, timestamp :string, reason: string): Promise<Appointment> { 

    let bodySearchParam = new URLSearchParams(); 
    bodySearchParam.append('userId', userId); 
    bodySearchParam.append('timestamp', this.datetotimestamp(timestamp).toString()); 
    bodySearchParam.append('reason', reason); 
    let body = bodySearchParam.toString(); 

    console.log(body) 
    return this.http.post(this.AppointmentUrlWrite,body) 
        .toPromise() 
        .then(response => 
        this.createdId = response.json().id // Get the appointment's ID 
       ) 
        .catch(this.handleError); 
    } 

讓誰返回createdID功能:

getCreatedId(){ 
    return this.createdId; 
    } 

,並在updateAppointment方法做到這一點:

if(e.appointmentData.id == null){e.appointmentData.id = this.appointmentService.getCreatedId();} 

條件服務於誰的已經任命有一個id(刷新頁面後所有約會都有一個id)

希望它可以爲另一個:)