-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpservice.html
More file actions
54 lines (46 loc) · 1.85 KB
/
httpservice.html
File metadata and controls
54 lines (46 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Headers, RequestOptions } from '@angular/http';
import { map } from "rxjs/operators";
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit {
private headers: Headers;
public dataURL: string = 'https://jsonplaceholder.typicode.com/';
public listAllUsers=[];
public searchUsers: string;
constructor(private httpClient: HttpClient) {
this.headers = new Headers()
this.headers.append('Accept', 'application/json')
this.headers.append('Accept', 'application/x-www-form-urlencoded')
this.headers.append('Content-Type', 'application/json')
this.headers.append('Content-Type', 'application/x-www-form-urlencoded')
this.headers.append('Access-Control-Allow-Origin', 'http://localhost:4200/')
this.headers.append('Access-Control-Allow-Credentials', 'false')
this.headers.append('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, HEAD')
this.headers.append('Access-Control-Allow-Origin', '*')
console.log('Hello RemoteServiceProvider Provider');
}
ngOnInit() {
this.getAllUsers();
}
//HTTP Service GET Method Coding
getAllUsers()
{
return this.httpClient.get(this.dataURL+'users').subscribe((res : any[])=>{
this.listAllUsers = res;
});
}
//HTTP Service POST Method Coding
// saveEnquiryDetails(enquiry: Enquiry)
// {
// let options = new RequestOptions({ headers: this.headers });
// return this.http.post(this.dataURL+'api/insertEnquiryDetails.php', enquiry, options)
// .map(res => res.json());
// }
}
In the app.module.ts we have to add this line and to the imports array
import { HttpClientModule } from '@angular/common/http';