Skip to content

Commit 58fa24d

Browse files
committed
angular http post
1 parent b5b888e commit 58fa24d

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

http-sample-app/src/app/app.component.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component, OnInit} from '@angular/core';
22
import {Observable} from "rxjs/Observable";
3-
import {HttpClient, HttpRequest} from "@angular/common/http";
3+
import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
44
import * as _ from 'lodash';
55

66

@@ -35,18 +35,40 @@ export class AppComponent implements OnInit {
3535
}
3636

3737
ngOnInit() {
38-
/*
38+
39+
40+
// Simple HTTP GET
41+
// this.courses$ = this.http
42+
// .get("https://angular-http-guide.firebaseio.com/courses.json")
43+
// .do(console.log)
44+
// .map(data => _.values(data));
45+
46+
47+
48+
49+
50+
51+
52+
//
53+
//const params = new HttpParams()
54+
// .set('orderBy', '"$key"')
55+
// .set('limitToFirst', "1");
56+
57+
//
58+
//const params = new HttpParams({fromString: 'orderBy="$key"&limitToFirst=1'});
59+
60+
const params = new HttpParams({fromString: 'orderBy="$key"&limitToFirst=1'});
61+
62+
const headers = new HttpHeaders().set("X-CustomHeader", "custom header value");
63+
3964
this.courses$ = this.http
40-
.get("https://angular-http-guide.firebaseio.com/courses.json")
65+
.get(
66+
"https://angular-http-guide.firebaseio.com/courses.json",
67+
{headers})
4168
.do(console.log)
42-
.map(data => _.values(data))
69+
.map(data => _.values(data));
4370

44-
*/
4571

46-
this.courses$ = this.http
47-
.request<Object>(new HttpRequest('GET', "https://angular-http-guide.firebaseio.com/courses.json", {responseType:'json'}))
48-
.map(data => _.values(data))
49-
.do(console.log);
5072

5173

5274
}

0 commit comments

Comments
 (0)