import { Injectable } from '@angular/core' ; import { Http } from '@angular/http' ; import { User } from '../poto/user' ; import { Observable } from 'rxjs/Rx' ; import 'rxjs/Rx' ; import { resolve } from 'dns' ; import { reject } from 'q' ; @ Injectable ( ) export class APIService { private userURL : string = "assets/users.json" ; constructor ( private http ) { } param { string } email param { string } password return { Promise < User > } public getUser ( email , password ) { console . log ( 'getUser' , email , password ) ; return this . http . get ( this . userURL ) . flatMap ( res => res . json ( ) . users ) . filter ( ( user ) => { console . log ( "filter" , user ) ; return ( user . email === email && user . password == password ) ; } ) . toPromise ( ) . then ( ( user ) => { console . log ( "map" , user ) ; return new User ( email , password ) ; } ) ; } param { string } email param { string } password return { Promise < User > } public postUser ( email , password ) { return new Promise < User > ( ( resolve , reject ) => { resolve ( new User ( email , password ) ) ; } ) ; } }