本文介绍了如何使用http在angular2中发出放置请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发这个angular2应用程序,并且正在执行CRUD操作.

I am working on this angular2 application and I am doing CRUD operations.

我有用于制作get&的http. post请求.

I have http for making get & post requests.

我现在想执行put操作,但是找不到任何相关的内容.

I want to perform put operation now but cannot find anything relevant.

有输入吗?

谢谢.

推荐答案

如果您已经熟悉POST,那么

POST和PUT请求之间的唯一区别实际上是UT而不是OST,对于前端至少是verb.

Only difference between POST and PUT request is literally UT instead of OST,it's just a verb, for front-end atleast.

Angular Docs(必须使其变得复杂)

// Update existing Hero
private put(hero: Hero) {
  let headers = new Headers();
  headers.append('Content-Type', 'application/json');

  let url = `${this.heroesUrl}/${hero.id}`;

  return this.http
             .put(url, JSON.stringify(hero), {headers: headers})
             .map(res => res.json());
}


记住-可观察对象可能是惰性的(例如:Angular的Http请求),因此即使您不想处理响应,也需要订阅它们以使请求执行. – @ user2171669


And remember - Observables can be lazy (eg: Angular's Http request) so you need to subscribe on them to make the request execute even if you don't want to handle the response. – @user2171669

这篇关于如何使用http在angular2中发出放置请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 05:45
查看更多