那么你的问题与HTTP
即来自客户端和服务器端的数据交换。
所以首先做同样的事情你必须添加http
文件在index.html
像这样的文件:
<script src="node_modules/angular2/bundles/http.dev.js"></script>
你必须添加HTTP_PROVIDERS
无论是在引导程序的连接处还是在提供程序列表中。
所以现在来RequestOptions, Headers etc
。首先根据需要从这里导入这些......
import {Http, Response, RequestOptions, Headers, Request, RequestMethod} from 'angular2/http';
标头的作用:
基本上 header 是用来追加的Content-Type
或某种机密数据,例如username,Password
,我们要发送到服务器。
我们也有主体部分,它也用于向服务器发送数据。例如:
this.headers = new Headers();
this.headers.append("Content-Type", 'application/json');
this.headers.append("Authorization", 'confidential data or
something like that')
请求选项:
基本上RequestOptions
是一些属性的集合,例如method
(获取、发布、放置......),url or path to json file etc
, Headers
body part
和更多。我们可以根据需要添加不同的选项。例如,这里是使用的示例RequestOptions
.
this.requestoptions = new RequestOptions({
method: RequestMethod.Post,
url: "url path....",
headers: this.headers,
body: JSON.stringify(data)
});
这是我找到的一些最好的教程。希望这可以帮助你。
@帕迪普。
http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http http://www.syntaxsuccess.com/viewarticle/angular-2.0-and-http
https://auth0.com/blog/2015/10/15/angular-2-series-part-3-using-http/ https://auth0.com/blog/2015/10/15/angular-2-series-part-3-using-http/
https://angular.io/docs/js/latest/api/http/Request-class.html https://angular.io/docs/js/latest/api/http/Request-class.html