Last active
December 4, 2018 14:00
-
-
Save fcschmidt/e57b8d687b17b67209d5396e04dbe3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClient, HttpHeaders, HttpHeaderResponse } from '@angular/common/http'; | |
import { Injectable } from '@angular/core'; | |
// import { Observable } from 'rxjs/Observable'; | |
// import { resolveDefinition } from '@angular/core/src/view/util'; | |
import 'rxjs/add/operator/map'; | |
/* | |
Generated class for the RestApiProvider provider. | |
See https://angular.io/guide/dependency-injection for more info on providers | |
and Angular DI. | |
*/ | |
@Injectable() | |
export class RestApiProvider { | |
private API_URL = "http://localhost:3000/api/user"; | |
constructor(private http: HttpClient) { | |
console.log('Hello RestApiProvider Provider'); | |
} | |
postPergamum(username: string, password: string) { | |
return new Promise((resolve, reject) => { | |
var data = { | |
"username": username, | |
"password": password | |
}; | |
let headers = new HttpHeaders(); | |
// headers.append("Content-type", "application/json"); | |
// let options = new HttpHeaderResponse({ headers: headers}); | |
headers.set("Content-Type", "application/json"); | |
this.http.post(this.API_URL, JSON.stringify(data), {headers: headers}) | |
.subscribe((result: any) => { | |
resolve(result.json()); | |
}, (error) => { | |
reject(error.json()); | |
}); | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment