Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Http } from '@angular/http';
  3. import 'rxjs/add/operator/map';
  4.  
  5. /*
  6. Generated class for the UsersService provider.
  7.  
  8. See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  9. for more info on providers and Angular 2 DI.
  10. */
  11. @Injectable()
  12. export class UsersService {
  13. data: any;
  14.  
  15. constructor(private http: Http) {
  16. this.data = null;
  17. }
  18.  
  19. autentication() {
  20. if (this.data) {
  21. // already loaded data
  22. return Promise.resolve(this.data);
  23. }
  24.  
  25. // don't have the data yet
  26. return new Promise(resolve => {
  27. var url = 'http://localhost/APIPortManager/login.php';
  28. // We're using Angular Http provider to request the data,
  29. // then on the response it'll map the JSON data to a parsed JS object.
  30. // Next we process the data and resolve the promise with the new data.
  31. this.http.get(url)
  32. .map(res => res.json())
  33. .subscribe(data => {
  34. // we've got back the raw data, now generate the core schedule data
  35. // and save the data for later reference
  36. this.data = data.results;
  37. resolve(this.data);
  38. });
  39. });
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement