Ionic framework 启动屏幕发出http请求并将响应传递到另一个页面
我试图做的是,当启动屏幕加载时,向服务器发出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
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