Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { Http } from '@angular/http';
- import 'rxjs/add/operator/map';
- /*
- Generated class for the UsersService provider.
- See https://angular.io/docs/ts/latest/guide/dependency-injection.html
- for more info on providers and Angular 2 DI.
- */
- @Injectable()
- export class UsersService {
- data: any;
- constructor(private http: Http) {
- this.data = null;
- }
- autentication() {
- if (this.data) {
- // already loaded data
- return Promise.resolve(this.data);
- }
- // don't have the data yet
- return new Promise(resolve => {
- var url = 'http://localhost/APIPortManager/login.php';
- // We're using Angular Http provider to request the data,
- // then on the response it'll map the JSON data to a parsed JS object.
- // Next we process the data and resolve the promise with the new data.
- this.http.get(url)
- .map(res => res.json())
- .subscribe(data => {
- // we've got back the raw data, now generate the core schedule data
- // and save the data for later reference
- this.data = data.results;
- resolve(this.data);
- });
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement