angular - PouchDB 关系型 pouch 和 pouchdb-find 与 Angular5/Typescript

标签 angular typescript plugins pouchdb

我正在使用 Angular5 项目测试 PouchDB。我想使用这些 pouchdb 插件:

pouchdb-find
relational-pouch

所以我知道如何导入 PouchDB:

import PouchDB from 'pouchdb';

我还知道如何导入 pouchdb-find 并添加到 PouchDB

import PouchDBFind from 'pouchdb-find';
PouchDB.plugin(PouchDBFind);

但接下来我还想添加关系袋插件:

import PouchDBRelational from 'relational-pouch';
PouchDB.plugin(PouchDBRelational);

Typescript 编译器会编译它,但我的浏览器出现错误:

index-browser.es.js:2780 Uncaught Error: Invalid plugin: got "undefined", expected an object or a function
at Function.PouchDB.plugin (index-browser.es.js:2780)
at eval (pouchdb.service.ts:8)
at Object../src/app/_services/pouchdb.service.ts (main.bundle.js:29)
at __webpack_require__ (inline.bundle.js:55)
at eval (farms.service.ts:2)
at Object../src/app/_services/farms.service.ts (main.bundle.js:21)
at __webpack_require__ (inline.bundle.js:55)
at eval (app.component.ts:1)
at Object../src/app/app.component.ts (main.bundle.js:59)
at __webpack_require__ (inline.bundle.js:55)
PouchDB.plugin @ index-browser.es.js:2780
(anonymous) @ pouchdb.service.ts:8
./src/app/_services/pouchdb.service.ts @ main.bundle.js:29
__webpack_require__ @ inline.bundle.js:55
(anonymous) @ farms.service.ts:2
./src/app/_services/farms.service.ts @ main.bundle.js:21
__webpack_require__ @ inline.bundle.js:55
(anonymous) @ app.component.ts:1
./src/app/app.component.ts @ main.bundle.js:59
__webpack_require__ @ inline.bundle.js:55
(anonymous) @ app.module.ts:1
./src/app/app.module.ts @ main.bundle.js:67
__webpack_require__ @ inline.bundle.js:55
(anonymous) @ main.ts:4
./src/main.ts @ main.bundle.js:215
__webpack_require__ @ inline.bundle.js:55
0 @ main.bundle.js:223
__webpack_require__ @ inline.bundle.js:55
webpackJsonpCallback @ inline.bundle.js:26
(anonymous) @ main.bundle.js:1

我也尝试过这个:

import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
import PouchDBRelational from 'relational-pouch';
PouchDB.plugin(PouchDBFind , PouchDBRelational);

浏览器中没有错误,但未找到关系袋中的方法:setSchema()。所以我怀疑插件没有加载?

最佳答案

OP 的解决方案

import PouchDB from 'pouchdb';
import PouchDBFind from 'pouchdb-find';
PouchDB.plugin(PouchDBFind);
import * as PouchDBRelational from 'relational-pouch';
PouchDB.plugin(PouchDBRelational);

关于angular - PouchDB 关系型 pouch 和 pouchdb-find 与 Angular5/Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48945764/

相关文章:

Angular 5 表单验证(必需)不起作用

javascript - Webpack 在与 typescript 的 react 中抛出错误 "You may need an appropriate loader"

javascript - 克隆对象后更新内部 Knockout 属性不起作用

javascript - 摘抄();函数不计算/处理日语单词

maven - 在 Maven 多模块项目中,如何禁用一个子项目中的插件?

scala - 如何编写 sbt 插件以通过代理启动应用程序

javascript - 位置 0 Angular2 的 JSON 中的 SyntaxError unexpected token u

angular - 模板继承和/或组合

javascript - typescript 中的绑定(bind)函数和 this

Angular Google map 无法呈现