daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Kolejność wywołania metod:
  2. // PostComponent.vote => VoteService.voteOnPost => VoteService.vote
  3. // czyli w sumie od góry do dołu
  4.  
  5.  
  6.  
  7. export class PostsComponent implements OnInit {
  8.   async vote(id: string) {
  9.     const post = this.posts.find(value => value.id === id);
  10.     const index = this.posts.indexOf(post);
  11.     const votes = await VoteService.voteOnPost(this.http, id)
  12.       .then(value => {
  13.         return value;
  14.       });
  15.     console.log(votes);
  16.     console.log(votes.votes);
  17.     this.posts[index] = post;
  18.   }
  19. }
  20.  
  21.  
  22.  
  23. export class VoteService {
  24.  static voteOnPost(http: HttpClient, id: string) {
  25.     return this.vote(http, 'post', id).then(value => {return value});
  26.   }
  27.  
  28.  
  29.   private static async vote(http: HttpClient, onWhat: string, id: string) {
  30.     const resp: any = new Post();
  31.     await http.get("http://localhost:8080/vote/" + onWhat + "/" + id,
  32.       {headers: {'Authorization': localStorage.getItem('Authorization')}})
  33.       .subscribe(
  34.         (response: number) => resp.votes = response,
  35.         error => console.log(error));
  36.     return resp;
  37.   }
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top