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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.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
Ionic framework 启动屏幕发出http请求并将响应传递到另一个页面_Ionic Framework_Ionic2 - Fatal编程技术网

Ionic framework 启动屏幕发出http请求并将响应传递到另一个页面

Ionic framework 启动屏幕发出http请求并将响应传递到另一个页面,ionic-framework,ionic2,Ionic Framework,Ionic2,我试图做的是,当启动屏幕加载时,向服务器发出http请求,以获取一些信息并将响应传递给另一个页面 下面是我正在使用的代码 import { Component } from '@angular/core'; import { Platform, LoadingController } from 'ionic-angular'; import { StatusBar, Splashscreen } from 'ionic-native'; import { CacheService } from

我试图做的是,当启动屏幕加载时,向服务器发出http请求,以获取一些信息并将响应传递给另一个页面

下面是我正在使用的代码

import { Component } from '@angular/core';
import { Platform, LoadingController } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { CacheService } from "ionic-cache/ionic-cache";
import { Apis } from './apis';

import { StayPage} from '../pages/stay/stay';

@Component({
  templateUrl: 'app.html',
  providers: [Apis]
})

export class MyApp {
  rootPage = StayPage;

  constructor(platform: Platform, cache: CacheService, public loadingCtrl: LoadingController, public Apis: Apis ) {
    cache.setDefaultTTL(60 * 60);
      platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.

      this.Apis.types().subscribe( response => {
        response.results;
        StatusBar.styleDefault();
        Splashscreen.hide();

      }, err => {
        this.Apis.error( err );
      });

    });
  }
}

当我运行上述代码时,启动屏幕在加载时被卡住,不会移动到其他页面。

您需要在constructor或StayPage的ngOnInit中发出HTTP请求

export class StayPage implements OnInit {
    ...

    constructor(public navCtrl: NavController, 
                public navParams: NavParams
                public http: Http) {  }

    ngOnInit(){
        this.http.get(apiUrl)
           .subscribe(
             responseSuccess => ...
             responseError => ...
        }
    }
} 

你想在StayPage上展示吗?@ACES是的。启动屏幕将发出HTTP请求并将响应发送到
StayPage