Tho*_*aut 8 typescript ionic-framework ionic2 ionic3 angular
我试图以这种方式使用最近添加的LoadingController:
let loading=this.load.create({
  content: "Connexion au serveur Migal en cours..."
});
loading.present();
this.http.get(this.urlCheckerForm.value.migalUrl+'/action/MobileApp/URLChecker')
  .map(res => res.json())
  .subscribe(
    data => this.newConnection(data,loading),
    error => this.catchURLError(loading));
loading.dismiss();
基本上,我只是想在我的页面加载之前显示我的加载pop-in,然后将其关闭.
我按照Ionic 2文档中的示例进行操作,但它似乎根本不起作用......
编辑:加载组件甚至没有出现.
seb*_*ras 15
你的代码的问题是你正在发出http请求,然后调用,dismiss()但dismiss()方法不等待http请求完成.请看看这个plunker.
代码几乎是不言自明的:
import { NavController, LoadingController } from 'ionic-angular/index';
import { Http, Response } from '@angular/http';
import { Component } from "@angular/core";
import 'rxjs/Rx';
@Component({
  templateUrl:"home.html"
})
export class HomePage {
  private users : Array<any>
  constructor(private http: Http, private loadingCtrl: LoadingController) {
    // Create the popup
    let loadingPopup = this.loadingCtrl.create({
      content: 'Loading data...'
    });
    // Show the popup
    loadingPopup.present();
    // Get the data
    this.http.get('https://jsonplaceholder.typicode.com/users')
      .map((res: Response) => res.json())
      .subscribe(
        data => {
          // I've added this timeout just to show the loading popup more time
          setTimeout(() => {
            this.users= data;
            loadingPopup.dismiss();
          }, 1000);
          // Should be just this:
          // this.users= data;
          // loadingPopup.dismiss();
        },
        err => console.error(err)
    );
  }
}
| 归档时间: | 
 | 
| 查看次数: | 12159 次 | 
| 最近记录: |