Guest User

Untitled

a guest
Jun 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import {Component, OnInit} from '@angular/core';
  2. import {Payment} from './Payment';
  3. import {HttpClient, HttpHeaders, HttpResponse} from '@angular/common/http';
  4. import {Token} from './Token';
  5.  
  6. @Component({
  7. selector: 'app-home',
  8. templateUrl: './home.component.html',
  9. styleUrls: ['./home.component.css']
  10. })
  11. export class HomeComponent implements OnInit {
  12.  
  13. title = 'Home';
  14. token: Token;
  15. payments: Payment[];
  16. jwt = '';
  17. constructor(private http: HttpClient) {
  18. }
  19.  
  20. ngOnInit() {
  21. this.getToken();
  22. console.log('dsdsd=>' + this.jwt);
  23.  
  24. }
  25.  
  26. getToken() {
  27.  
  28. this.http.post<Token>('http://localhost:8084/login', JSON.stringify({ username: 'mehman', password: 'mehman' })
  29. )
  30. .subscribe(res => {
  31. this.token = res.token;
  32. this.getPayments(res.token);
  33. });
  34. }
  35.  
  36. getPayments(token: Token) {
  37. console.log(token);
  38. const headers = new HttpHeaders().set('Content-Type', 'application/json')
  39. .set('Authorization', '' + token);
  40. this.http.get<Payment[]>('http://localhost:8084/payment/all', { headers: headers}
  41. )
  42. .subscribe(res => {
  43. this.payments = res;
  44. console.log(res);
  45. });
  46. }
  47. }
Add Comment
Please, Sign In to add comment