user-data-service.ts 2.32 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
import {Http, Headers} from '@angular/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';
import { IStudentDataField } from '../store/studentdatafields/studentdatafields.types';
import {AppSettings} from '../app.settings';

const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };

@Injectable()
export class UserDataService {
    constructor(private http: Http) {
    };
    getStudentDataFields() {

        return new Promise((resolve, reject) => {
            this.http.get(`${AppSettings.API_ENDPOINT}/studentList`)
            .map(response => <IStudentDataField[]>response.json())
            .subscribe(data => {
                resolve(data);
            }, // put the data returned from the server in our variable
            error => {
                console.log("Error HTTP GET Service"); // in case of failure show this message
                reject("Error HTTP GET Service");
            },
            () => console.log("Student Data Fields Received"));//run this code in all cases); */
        });
    };
}


/*
import {Http, Headers} from '@angular/http';
import {Injectable} from '@angular/core';
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';
//import { ICourseField } from '../store/coursefields/coursefields.types';
import { IStudentDataField } from '../store/studentdatafields/studentdatafields.types';
import {AppSettings} from '../app.settings';

const HEADER = { headers: new Headers({ 'Content-Type': 'application/json' }) };

@Injectable()
//export class HelperDataService {
export class UserDataService {
    constructor(private http: Http) {
    };
    getStudentDataFields() {

        return new Promise((resolve, reject) => {
            //this.http.get(`${AppSettings.API_ENDPOINT}/coursefields/list`)
            this.http.get(`${AppSettings.API_ENDPOINT}/studentList`)
            .map(response => <IStudentDataField[]>response.json())
            .subscribe(data => {
                console.log(data);
                resolve(data);
            },
            error => {
                console.log("Error HTTP GET Service"); // in case of failure show this message
                reject("Error HTTP GET Service");
            },
            () => console.log("Student Fields Received"));
        });
    };
}
*/