【问题标题】:Ionic 5 Angular Sqlite: Uncaught in PromiseIonic 5 Angular Sqlite:在 Promise 中未捕获
【发布时间】:2020-12-10 09:42:05
【问题描述】:

我正在尝试在 ionic 5 Angular 中创建数据库,但在调用 .then() 方法时出现 Uncaught (in promise) 错误

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'then' of undefined
TypeError: Cannot read property 'then' of undefined

错误出现在构造函数中调用的 createDB() 函数中

export class UniversalService {
    private database: SQLiteObject;
    employeelist = new BehaviorSubject([]);
    private dbReady: BehaviorSubject<boolean> = new BehaviorSubject(false);

    constructor(
        private plt: Platform,
        private sqlite: SQLite,
        private sqlPorter: SQLitePorter,
    ) {
        this.plt.ready().then(() => {
            return this.createDB()
        });
    }

    createDB() {
        this.sqlite.create({
            name: 'emp.db',
            location: 'default'
        })
//////////////////////////////////////////////////////
GETTING ERROR HERE
//////////////////////////////////////////////////////
            .then((db: SQLiteObject) => {
                this.database = db;
                alert("created!!")
            })
            .catch(e => {
                alert("error " + JSON.stringify(e))
            });
    }
...

【问题讨论】:

    标签: angular database sqlite ionic-framework promise


    【解决方案1】:

    Cordova-sqlite-storage 只能在本机设备(iOS/Android/Electron)上使用,很遗憾您不能在浏览器中使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-16
      • 2017-06-05
      • 1970-01-01
      • 2018-01-14
      • 1970-01-01
      • 2018-01-27
      相关资源
      最近更新 更多