我有一个 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/