Refer:
Https://angular.cn/docs/ts/latest/guide/server-communication.html
Https://xgrommx.github.io/rx-book/index.html
There is not much difference in concept.
Here are some examples and small differences:
Different places:
1. Upload file is not supported (XHR of the browser can be easily implemented via the Send FormData Ajax upload), Ng2 no
2. Interceptor interception and transformations are not supported for ng1 (you can try to extend it by inheriting the HTTP service)
3. The default combination of RXJS (can also be easily converted back to the familiar Promise)
Remind:
1.XSRF and Ng1 are identical
2.ng2 has a Memory WebAPI service (In-memory Web API Services) that can emulate the backend Web API server
Example:
1.Headers and Params
New Headers ({"MyHeader": "MyValue" }) Headers.append ("Yourheader", "Yourvalue"new Urlsearchparams ();p arams.set (' myparam ', ' myvalue 'new requestoptions ({headers:headers, Search:params}); this. Http.get ("/api/products", Options). topromise (). Then ((response) = {
2.POST
Let BODY = json.stringify ({ "mk200"new Headers ({' Content-type ': ' Application/json ' New requestoptions ({headers:headers}); this. Http.post ("/api/products", body, Options). topromise (). Then (response) = {// do something...});
3.get CSV
New requestoptions ({responseType:ResponseContentType.Text}); this. Http.get ("/demo.csv", Options). topromise (). Then ((response) = { Console.log ( Response.text ());
4.by Request
New requestoptions ({ method:RequestMethod.Post, "/api/products", new Headers ({' Content-type ': ' Application/json ' }), " mk200 " })}); this. Http.request ( options). topromise (). Then ((response) = { //dosomething ...});
ANGULAR2 Learning Notes (Http requests)