|
1 | 1 | import {Component, OnInit} from '@angular/core'; |
2 | 2 | import {Observable} from "rxjs/Observable"; |
3 | | -import {HttpClient, HttpRequest} from "@angular/common/http"; |
| 3 | +import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http"; |
4 | 4 | import * as _ from 'lodash'; |
5 | 5 |
|
6 | 6 |
|
@@ -35,18 +35,40 @@ export class AppComponent implements OnInit { |
35 | 35 | } |
36 | 36 |
|
37 | 37 | 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 | + |
39 | 64 | 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}) |
41 | 68 | .do(console.log) |
42 | | - .map(data => _.values(data)) |
| 69 | + .map(data => _.values(data)); |
43 | 70 |
|
44 | | -*/ |
45 | 71 |
|
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); |
50 | 72 |
|
51 | 73 |
|
52 | 74 | } |
|
0 commit comments