Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 如何在ionic中从服务器获取数据_Typescript_Ionic Framework_Ionic2 - Fatal编程技术网

Typescript 如何在ionic中从服务器获取数据

Typescript 如何在ionic中从服务器获取数据,typescript,ionic-framework,ionic2,Typescript,Ionic Framework,Ionic2,在爱奥尼亚的地狱里,我已经走出了我的深渊。下面是我当前的代码,它返回一个可观察的。我需要它从服务器返回响应(出于分离关注点的目的,它位于单独的文件中) auth.ts import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; export const getToken = function(http){ let response = http.post('localhost:3000/auth/authe

在爱奥尼亚的地狱里,我已经走出了我的深渊。下面是我当前的代码,它返回一个可观察的。我需要它从服务器返回响应(出于分离关注点的目的,它位于单独的文件中)

auth.ts

import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

export const getToken = function(http){
    let response = http.post('localhost:3000/auth/authenticate', 
                {email: 'mendelh1537@gmail.com', password: 'password'}).then();
    return response();
}
export const getToken = function(http){
    return http.post('localhost:3000/auth/authenticate', 
                {email: 'mendelh1537@gmail.com', password: 'password'});
}
home.ts

constructor(public events: Events, public http: Http,
    ...

smsPressed(item){
    console.log(getToken(this.http));
}
constructor(public events: Events, public http: Http,
    ...

smsPressed(item){
    getToken(this.http).subscribe(token => {
         console.log(token);   
    })
}
错误


Http.post
不返回
Promise
它返回
可观察的

auth.ts

import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

export const getToken = function(http){
    let response = http.post('localhost:3000/auth/authenticate', 
                {email: 'mendelh1537@gmail.com', password: 'password'}).then();
    return response();
}
export const getToken = function(http){
    return http.post('localhost:3000/auth/authenticate', 
                {email: 'mendelh1537@gmail.com', password: 'password'});
}
home.ts

constructor(public events: Events, public http: Http,
    ...

smsPressed(item){
    console.log(getToken(this.http));
}
constructor(public events: Events, public http: Http,
    ...

smsPressed(item){
    getToken(this.http).subscribe(token => {
         console.log(token);   
    })
}