Angular 和 PouchDBFind 插件

标签 angular typescript pouchdb typescript-typings

我有一个 Angular 应用程序,我想在其中使用 PouchDB 和 PouchDBFind 插件。

我已经让 PouchDB 开始工作了。但我不知道如何使用 PouchDB 插件。

数据库设置示例:

constructor() {
    this.db = new PouchDB('exampleDb');
    this.db.createIndex({
        index: {fields: ['number', 'name']}
    }).catch(error => {
        console.log(error);
    });
}

我总是收到此错误:

ERROR Error: Uncaught (in promise): TypeError: this.db.createIndex is not a function 
TypeError: this.db.createIndex is not a function

这就是我的导入语句:

import * as PouchDB from 'pouchdb';
import * as PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);

我在这里没有收到任何错误。

我已经阅读过另一种导入替代方案,但这不起作用:

import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';

我收到此错误:

"pouchdb-find" has no default export

我已经安装了打字功能。 这是我的 package.json 依赖项:

"dependencies": {
    "@types/pouchdb": "6.1.1",
    "@types/pouchdb-find": "^0.10.1",
    "pouchdb": "^6.2.0",
    "pouchdb-find": "^6.3.4"
},

那么如何让 PouchDBFind 插件发挥作用呢? 如果需要更多信息,请通知我。

提前致谢!

编辑: 将版本锁定后...

"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4",

... webpack 编译后出现以下警告:

WARNING in ./src/app/services/example-db/example-db.service.ts
17:8-22 "export 'plugin' (imported as 'PouchDB') was not found in 'pouchdb'

在浏览器控制台中:

ERROR Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_2_pouchdb__.plugin is not a function
TypeError: __WEBPACK_IMPORTED_MODULE_2_pouchdb__.plugin is not a function

当我评论 PouchDB.plugin(PouchFind) 行时,警告消失了,但控制台中的错误仍然存​​在。它只是说它没有构造函数。

编辑:这是一个 angular-cli 项目。

最佳答案

您可以将版本锁定到...

"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4"

...然后重试以下内容?

import PouchFind from 'pouchdb-find';
import PouchDB from 'pouchdb-browser';

PouchDB.plugin(PouchFind);

关于Angular 和 PouchDBFind 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45165990/

相关文章:

javascript - PouchDB,如何在已有附件的文档中添加新附件?

angular - 使用 Angular Material 和柔性布局固定标题

angular - ng-bootstrap 日期选择器不工作

typescript - 为什么 makeStyles 和 createStyles 必须分开(Material UI + TypeScript)?

angular - 如何在 Angular2 中将 CSS 类作为输入传递?

angular - 如何使用 ion-col 响应式设置大型动态表数据

javascript - 如何加密 pouchdb 数据库

javascript - 基于JSON对象动态创建表单

javascript - 复制表格的一部分

Pouchdb文档id复杂键