AlertController Ionic 2 Uncaught (in promise): the pasted view has already been destroyed

Initiating an Ion 2 AlertController on the same page gives this error: Not shown (in promise): the inserted view has already been destroyed

I would like it to run several times, equal to the instance of the ionic 1 alert, which can be called several times on the same page.

Code:

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(); }); } } 
+5
source share
1 answer

This problem is related to reusing the load object in your function.

Since you would "like to run it several times," the download object will also be reused. However, this object can only be used once. Check here .

Try:

 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(); }); } 
+18
source

Source: https://habr.com/ru/post/1268193/


All Articles