Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Http, Response, Headers } from '@angular/http';
  3. import { Observable } from 'rxjs/Rx';
  4. import { User } from './user';
  5.  
  6. @Injectable()
  7.  
  8. export class UserService {
  9.  
  10. public usersTmp: Array<Object> = new Array<Object>();
  11. public users: Array<User>;
  12. public user: User = new User();
  13. public noteToSend;
  14. constructor(private http: Http) { }
  15.  
  16. getUsers() {
  17. var headers = new Headers();
  18. headers.append('Accept', 'q=0.8;application/json;q=0.9');
  19.  
  20. this.http.get('/AngularApp/api/users', { headers: headers })
  21. .map((res: Response) => res.json())
  22. .subscribe(
  23. data => {
  24. console.log(data);
  25. this.usersTmp = data;
  26. },
  27. err => console.error(err),
  28. () => console.log('done')
  29. );
  30.  
  31. this.users = new Array<User>();
  32. for (var i = 0; i < this.usersTmp.length; i++) {
  33. this.user = new User();
  34. this.user.id = this.usersTmp[i]["userId"];
  35. this.user.name = this.usersTmp[i]["userName"];
  36. this.user.email = this.usersTmp[i]["userEmail"];
  37. this.user.pass = this.usersTmp[i]["userPassword"];
  38.  
  39. this.users.push(this.user);
  40.  
  41. }
  42. return this.users;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement