首页 > 解决方案 > 在 IONIC 中遇到未处理的 Promise Rejection 问题

问题描述

测试:我实际上正在使用我的手机,使用 ionic cordova run android -l 并使用 chrome://inspect im 调试应用程序。

当我访问 datosparte 页面时,它会在控制台中打印:

zone.js:1102 
Unhandled Promise rejection: 
   {rows: {…}, rowsAffected: 1, insertId: 6736}
   insertId: 6736rows: {length: 0, item: ƒ}
   rowsAffected: 1[[Prototype]]: Object ; 
   Zone: <root> ; Task: null ; 
   Value: {rows: {…}, rowsAffected: 1, insertId: 6736} 
   undefined

这是我用来访问该页面的代码:

leerParte(parte){
    this.datos.removeTpmParte();
    this.datos.addTmpParte(parte.id);
    this.navCtrl.navigateForward('datosparte');
}

removeTpmParte() 会:

removeTpmParte(){
    this.database.executeSql("DELETE FROM tmpparte");
}

addTmpParte(id) 会:

addTmpParte(id) {
    let data = [id];
    return this.database.executeSql('INSERT OR REPLACE INTO tmpparte (id) VALUES (?)', data).then(data => {
    });
}

最后,页面 datosparte 会:

import { Component, OnInit } from '@angular/core';
import { alert } from '../services/alert';
import { api } from '../services/api';
import { datos } from '../services/datos';

@Component({
selector: 'app-datosparte',
templateUrl: './datosparte.page.html',
styleUrls: ['./datosparte.page.scss'],
providers: [datos, api, alert]
})
export class DatospartePage implements OnInit {

    constructor(private datos:datos, private api: api, private alert: alert) { }
    idParte:any
    url:string
    json:any
    datosParte:any
    fotosParte:any
    histoParte:any

    ngOnInit() {
        this.url = "https://NotARealURL.com/?f=partes.get&id="
        this.datos.getDatabaseState().subscribe(rdy => {
            if (rdy) {
                this.datos.getTmpPartes().subscribe(idParte => {
                    this.idParte = idParte[0];
                    this.getDatos(this.idParte);
                })
            }
        });
    }

    async getDatos(idParte){
        if(typeof idParte === "undefined")return
        let getDatosParte = this.url+idParte.id
        
        console.log(getDatosParte)
        this.api.getUrl(getDatosParte)
        this.json = await this.api.getUrl(getDatosParte);
        this.datosParte=[];
        if(this.json.error['id'] != 0){
            this.alert.showAlert("Error.", this.json.error['msg']);
            return;
        }
        this.datosParte = this.json.parte.datos;
        this.fotosParte = this.json.parte.fotos;
        this.histoParte = this.json.parte.historico;
        // console.log(this.datosParte);
        // console.log(this.fotosParte);
        // console.log(this.histoParte);
    }
}

标签: androidangulartypescriptionic-frameworkpromise

解决方案


推荐阅读