AlertController离子2未捕获(在承诺中):插入的视图已被破坏 [英] AlertController Ionic 2 Uncaught (in promise): inserted view was already destroyed
本文介绍了AlertController离子2未捕获(在承诺中):插入的视图已被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在同一页面上实例化Ionic 2 AlertController会出现此错误:未捕获(在承诺中):已插入视图已被销毁
Instantiating the Ionic 2 AlertController on the same page it gives this error: Uncaught (in promise): inserted view was already destroyed
我想让它运行几次等于离子1警报实例,可以在同一页面上多次调用。
I would like to make it run several times equal to the ionic 1 alert instance that can be called several times on the same page.
代码:
export class ConsultaProdutoPage {
public usar_leitor: boolean = false;
public codigo: string = '';
public icon: object = { 'icon': 'search', 'text': 'Buscar' };
public mostrar_produto: boolean = false;
private loading;
private _alert: Alert;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private _barcodeScanner: BarcodeScanner,
private _alertCtrl: AlertController,
private _service: consultaProdutoService,
private _loadingCtrl: LoadingController) {
this.loading = this._loadingCtrl.create({
content: 'Buscando Produtos. Aguarde...',
dismissOnPageChange: true
});
this._alert = this._alertCtrl.create({
'title': "Aviso",
'message': 'Erro ao buscar produtos.',
buttons: ['OK']
});
}
buscaProduto(codigo) {
this.loading.present();
this._service.getProduto(this.codigo)
.then(success => {
console.log(success);
})
.catch(err => {
this.loading.dismiss();
this.codigo = '';
this._alert.present();
});
}
}
推荐答案
这个问题是因为在你的函数中重用加载对象。
This issue is because of reuse of loading object in your function.
既然你会喜欢让它运行几次,加载对象也被重用了。但是,此对象只能使用一次。查看此处。
Since you " would like to make it run several times ", the loading object is also getting reused. However this object can only be used once. Check here.
尝试:
buscaProduto(codigo) {
this.loading = this._loadingCtrl.create({
content: 'Buscando Produtos. Aguarde...',
dismissOnPageChange: true
});
this.loading.present();
this._service.getProduto(this.codigo)
.then(success => {
console.log(success);
})
.catch(err => {
this.loading.dismiss();
this.codigo = '';
this._alert.present();
});
}
这篇关于AlertController离子2未捕获(在承诺中):插入的视图已被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文