Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {Component, OnInit} from '@angular/core';
- import {Payment} from './Payment';
- import {HttpClient, HttpHeaders, HttpResponse} from '@angular/common/http';
- import {Token} from './Token';
- @Component({
- selector: 'app-home',
- templateUrl: './home.component.html',
- styleUrls: ['./home.component.css']
- })
- export class HomeComponent implements OnInit {
- title = 'Home';
- token: Token;
- payments: Payment[];
- jwt = '';
- constructor(private http: HttpClient) {
- }
- ngOnInit() {
- this.getToken();
- console.log('dsdsd=>' + this.jwt);
- }
- getToken() {
- this.http.post<Token>('http://localhost:8084/login', JSON.stringify({ username: 'mehman', password: 'mehman' })
- )
- .subscribe(res => {
- this.token = res.token;
- this.getPayments(res.token);
- });
- }
- getPayments(token: Token) {
- console.log(token);
- const headers = new HttpHeaders().set('Content-Type', 'application/json')
- .set('Authorization', '' + token);
- this.http.get<Payment[]>('http://localhost:8084/payment/all', { headers: headers}
- )
- .subscribe(res => {
- this.payments = res;
- console.log(res);
- });
- }
- }
Add Comment
Please, Sign In to add comment