daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export class PostsComponent implements OnInit {
  2.  
  3.   async vote(id: string) {
  4.     const post = this.posts.find(value => value.id === id);
  5.     const index = this.posts.indexOf(post);
  6.     const votes = await VoteService.voteOnPost(this.http, id)
  7.       .then(value => {
  8.         return value;
  9.       });
  10.     console.log(votes);
  11.     console.log(votes.votes);
  12.     // post.votes = ;
  13.     this.posts[index] = post;
  14.   }
  15. }
  16.  
  17.  
  18.  
  19. export class VoteService {
  20.  static voteOnPost(http: HttpClient, id: string) {
  21.     return this.vote(http, 'post', id).then(value => {return value});
  22.   }
  23.  
  24.  
  25.   private static async vote(http: HttpClient, onWhat: string, id: string) {
  26.     const resp: any = new Post();
  27.     await http.get("http://localhost:8080/vote/" + onWhat + "/" + id,
  28.       {headers: {'Authorization': localStorage.getItem('Authorization')}})
  29.       .subscribe(
  30.         (response: number) => resp.votes = response,
  31.         error => console.log(error));
  32.     return resp;
  33.   }
  34. }
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