update(url: string, data: Object): Promise<Application> {
return this.http
.put(url, JSON.stringify(data), {headers: this.headers})
.toPromise()
.then(() => data)
.catch(this.handleError);
}
Using the above function with a valid URL results in the following exception:
EXCEPTION: Uncaught (in promise): Response with status: 400 Bad Request for URL: null
I am using the @angular/http
module to perform the request. The strange thing about this problem is that other methods of the module work fine ( GET
, POST
and DELETE
).
I am using the following header 'Content-Type': 'application/json'
and the InMemoryWebApiModule
to mock a response.
Calling the put function with a hard-coded value such as the following example results in the same exception.
this.http
.put('app/applications/1', JSON.stringify(data), {headers: this.headers})
.toPromise()
.then(() => data)
.catch(this.handleError);
I had the same problem recently. The reason for this was that my data hadn't field named id , which uniquely identify each item. The module @angular/http matches requested data by its id.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.