我在单页呼叫两个api呼叫。但如果我使用一个api称其工作正常。但如果我在同一页面使用两个api调用。我在运行时遇到错误。
错误未捕获(在承诺中):找不到removeView。
我也有一个疑问。哪里我去任何屏幕。如果我想回到我的主屏幕。我需要显示一个名为Data的Api来显示。所以我需要在构造函数或ionViewDidEnter
中调用我的Api调用方法。我在ionViewDidEnter
做了我没有表明这可能是我错误的原因。
以下是我的代码:
import { Component, ViewChild } from '@angular/core';
import { AlertController, App, FabContainer, ItemSliding, List, ModalController, NavController, ToastController, LoadingController, Refresher } from 'ionic-angular';
import { CategoryDetailPage } from '../categorydetail/categorydetail';
import { ConferenceData } from '../../providers/conference-data';
import { UserData } from '../../providers/user-data';
import { SessionDetailPage } from '../session-detail/session-detail';
import { ScheduleFilterPage } from '../schedule-filter/schedule-filter';
import {Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import { AuthService } from '../../providers/AuthService';
@Component({
selector: 'page-speaker-list',
templateUrl: 'speaker-list.html'
})
export class SpeakerListPage {
loading: any;
data: any;
Catdata: any;
Catdatanames: any;
resdata: any;
resCatdata: any;
resCatdatanames: any;
loginData: {username?: string} = {};
resloginData: {username?: string} = {};
constructor(
public alertCtrl: AlertController,
public app: App,
public loadingCtrl: LoadingController,
public modalCtrl: ModalController,
public navCtrl: NavController,
public toastCtrl: ToastController,
public confData: ConferenceData,
public user: UserData,
public http:Http,
public authService: AuthService) { }
ionViewDidEnter() {
this.show();
this.another();
}
show() {
this.showLoader();
this.authService.subs(this.loginData).then((result) => {
this.loading.dismiss();
this.data = result;
if(this.data.status == 1)
{
this.Catdata = this.data.SubjectList;
for(let i=0; i<this.Catdata.length; i++) {
console.log(this.Catdata[i].SubjectName);
}
}
else if(this.data.status == 0) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
this.loading.dismiss();
});
}
another() {
this.showLoader();
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) {
let alert = this.alertCtrl.create({
title: 'Error',
subTitle: 'Please Enter Valid Username & Password',
buttons: ['OK']
});
alert.present();
}
}, (err) => {
this.loading.dismiss();
});
}
showLoader(){
this.loading = this.loadingCtrl.create({
content: 'Authenticating...'
});
this.loading.present();
}
}
请帮帮我。如何解决我的问题?
我的离子信息 :
Cordova CLI: 6.5.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.3.5
ios-deploy version: 1.9.0
ios-sim version: 5.0.13
OS: macOS Sierra
Node Version: v7.3.0
Xcode version: Xcode 8.3.2 Build version 8E2002
帮助将非常有用。谢谢
答案 0 :(得分:1)
我知道这个问题是在一个多月前提出的!
我正在经历同样的问题并且我解决了这个问题。
我已将Note: If you're opening a URI with special characters, such as spaces, you need to encode the URI with urlencode().发布在另一个stackoverflow answer中。
部分Question可以了解问题。
注意: 如果你手动调用this.loading.dismiss(),我不建议使用dismissOnPageChange,你可能会解雇 相同的加载两次。
我认为this.loading.present()是异步方法。所以我们不能 this.loading.present()是手动调用this.loading.dismiss() 还在跑步。
因此,如果我们需要手动解雇,我们需要确保加载 提出并考虑解雇它,我们应该使用其他方法 在present()之后。然后就像我下面的代码一样。
public searchClick() {
this.createLoader();
this.loading.present().then(() => {
this.searchService.submitRequest(params, data)
.subscribe(response => {
this.loading.dismiss(); // Dismissing the loader manually.
//Call the other function
//You can dismiss loader here
//You can dismiss loader in other functions too by calling it from here, Since the scope will be available to that also.
}, error => {
this.loading.dismiss();
this.errorMessage = <any>error
});
});
}
createLoader(message: string = "Please wait...") { // Optional Parameter
this.loading = this.loadingCtrl.create({
content: message
});
}
如果您仍有问题,我希望这可以帮助您解决问题。
答案 1 :(得分:1)
问题原因: 有多次调用来解除加载组件的方法。
<强>解决方案:强> 在创建加载器时,检查加载器实例是否不 已存在,然后再创建另一个实例。
同样,在解除加载器时,检查加载器实例是否存在,然后才解除它。
<强>代码:强>
constructor(private _loadingCtrl: LoadingController){}
loading;
showLoading() {
if(!this.loading){
this.loading = this._loadingCtrl.create({
content: 'Please Wait...'
});
this.loading.present();
}
}
dismissLoading(){
if(this.loading){
this.loading.dismiss();
this.loading = null;
}
}
答案 2 :(得分:0)
我使用这种方法解决了以下问题。
this.loading.dismissAll();
答案 3 :(得分:0)
我有同样的错误,这是由于意外地让两个处理程序开火造成的。一个是作为ngSubmit属性的表单的一部分,另一个是自定义保存按钮。删除其中一个解决了它。