Angular 离子2数据显示了一些时间,一些时间没有

Angular 离子2数据显示了一些时间,一些时间没有,angular,typescript,ionic-framework,ionic2,hybrid-mobile-app,Angular,Typescript,Ionic Framework,Ionic2,Hybrid Mobile App,我已经搜索并执行了一些API调用来显示数据。但现在,当我在浏览器或android设备中运行时,有时它会显示,有时它不会显示,这意味着数据尚未加载到屏幕中 以下是我的两屏完整代码,包括API调用: Mysrc/provider/authservices.ts下的My api调用代码: import { Injectable } from '@angular/core'; import { Http, Headers } from '@angular/http'; import 'rxjs/add/

我已经搜索并执行了一些API调用来显示数据。但现在,当我在浏览器或android设备中运行时,有时它会显示,有时它不会显示,这意味着数据尚未加载到屏幕中

以下是我的两屏完整代码,包括API调用:

My
src/provider/authservices.ts下的My api调用代码

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';


let apiUrl = 'http://www.example.com/api/';
@Injectable()
export class AuthService {
data: any;

  constructor(public http: Http) {}
 categ(cat: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'categories.php', JSON.stringify(cat), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

   allresources(allres: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'AllResources.php', JSON.stringify(allres), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

}
this.authService.categ(this.loginData).then((result) => {
      this.loading.dismiss();
      this.data = result;

       if(this.data.status == 1)
       {
       this.Catdata = this.data.CatgeoryList;


           for(let i=0; i<this.Catdata.length; i++) {
               //console.log(this.Catdata[i].CategoryName);
           }

       }

       else if(this.data.status == 0) {


       }

    }, (err) => {
      this.loading.dismiss();

    }); 

opndetailpage() {
  console.log("button pressed");
  //this.navCtrl.push(SpeakerListPage, ResourcePage);

  this.navCtrl.push(SpeakerListPage).then(
      response => {
        console.log('Response ' + response);
      },
      error => {
        console.log('Error: ' + error);
      }
    ).catch(exception => {
      console.log('Exception ' + exception);
    });
}
this.authService.allresources(this.resloginData).then((result) => {
   this.loading.dismiss();

      this.resdata = result;

       if(this.resdata.status == 1)
       {
       this.resCatdata = this.resdata.SubjectList;
           for(let i=0; i<this.resCatdata.length; i++) {
              // console.log(this.resCatdata[i].FileName);
           }



       }

       else if(this.resdata.status == 0) {

       }

    }, (err) => {
      this.loading.dismiss();
    console.log(err);

    });
接下来是我的
schudle.ts

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';


let apiUrl = 'http://www.example.com/api/';
@Injectable()
export class AuthService {
data: any;

  constructor(public http: Http) {}
 categ(cat: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'categories.php', JSON.stringify(cat), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

   allresources(allres: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'AllResources.php', JSON.stringify(allres), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

}
this.authService.categ(this.loginData).then((result) => {
      this.loading.dismiss();
      this.data = result;

       if(this.data.status == 1)
       {
       this.Catdata = this.data.CatgeoryList;


           for(let i=0; i<this.Catdata.length; i++) {
               //console.log(this.Catdata[i].CategoryName);
           }

       }

       else if(this.data.status == 0) {


       }

    }, (err) => {
      this.loading.dismiss();

    }); 

opndetailpage() {
  console.log("button pressed");
  //this.navCtrl.push(SpeakerListPage, ResourcePage);

  this.navCtrl.push(SpeakerListPage).then(
      response => {
        console.log('Response ' + response);
      },
      error => {
        console.log('Error: ' + error);
      }
    ).catch(exception => {
      console.log('Exception ' + exception);
    });
}
this.authService.allresources(this.resloginData).then((result) => {
   this.loading.dismiss();

      this.resdata = result;

       if(this.resdata.status == 1)
       {
       this.resCatdata = this.resdata.SubjectList;
           for(let i=0; i<this.resCatdata.length; i++) {
              // console.log(this.resCatdata[i].FileName);
           }



       }

       else if(this.resdata.status == 0) {

       }

    }, (err) => {
      this.loading.dismiss();
    console.log(err);

    });
现在是我的
详细信息页面。ts

import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';


let apiUrl = 'http://www.example.com/api/';
@Injectable()
export class AuthService {
data: any;

  constructor(public http: Http) {}
 categ(cat: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'categories.php', JSON.stringify(cat), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

   allresources(allres: any) {
    return new Promise((resolve, reject) => {
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');

        this.http.post(apiUrl+'AllResources.php', JSON.stringify(allres), {headers: headers})
          .subscribe(res => {
            resolve(res.json());
          }, (err) => {
            reject(err);
          });
    });
  }

}
this.authService.categ(this.loginData).then((result) => {
      this.loading.dismiss();
      this.data = result;

       if(this.data.status == 1)
       {
       this.Catdata = this.data.CatgeoryList;


           for(let i=0; i<this.Catdata.length; i++) {
               //console.log(this.Catdata[i].CategoryName);
           }

       }

       else if(this.data.status == 0) {


       }

    }, (err) => {
      this.loading.dismiss();

    }); 

opndetailpage() {
  console.log("button pressed");
  //this.navCtrl.push(SpeakerListPage, ResourcePage);

  this.navCtrl.push(SpeakerListPage).then(
      response => {
        console.log('Response ' + response);
      },
      error => {
        console.log('Error: ' + error);
      }
    ).catch(exception => {
      console.log('Exception ' + exception);
    });
}
this.authService.allresources(this.resloginData).then((result) => {
   this.loading.dismiss();

      this.resdata = result;

       if(this.resdata.status == 1)
       {
       this.resCatdata = this.resdata.SubjectList;
           for(let i=0; i<this.resCatdata.length; i++) {
              // console.log(this.resCatdata[i].FileName);
           }



       }

       else if(this.resdata.status == 0) {

       }

    }, (err) => {
      this.loading.dismiss();
    console.log(err);

    });
this.authService.allresources(this.resloginda)。然后((结果)=>{
this.loading.disclose();
this.resdata=结果;
if(this.resdata.status==1)
{
this.resCatdata=this.resdata.SubjectList;
for(设i=0;i{
this.loading.disclose();
控制台日志(err);
});

就是这样。有时如果我也导航到详细信息页面,一些时间数据不会显示。我是错误地调用API还是需要添加一些加载的数据?

您使用Promise总结结果而不是返回Observable有什么原因吗?您可以看一看官方示例:@SathishAL让我澄清您的问题。最初,您可以使用Ionic1而不是ionic 2。它具有所有的功能。但有时,这种导航问题在ionic 2中会出现。最好从头再来一次以实现它。@hybridDev不,我尝试了7次以上,但我得到了相同的问题。因为您有任何源代码或任何机构面临这种问题issues@SathishAL甚至我也有这种导航填充数据的问题。不仅对你来说…这是离子2的常见问题。仍然没有解决。你可以看看离子1,或者你必须单独做模块,如登录、注册、侧菜单、选项卡。然后将两者集成。但我不确定你是否会再次出现此问题。因此最好使用离子1并购买一些插件达到你的目标