本文介绍了带有Angular5/Typescript的PouchDB关系包和pouchdb查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

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

I'm testing PouchDB with an Angular5 project. I want to use these pouchdb plugins:

pouchdb-find
relational-pouch

所以我知道如何导入PouchDB:

So I know how to import PouchDB:

import PouchDB from 'pouchdb';

我也知道如何导入pouchdb查找并添加到PouchDB

I also know how to import the pouchdb-find and add to PouchDB

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

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

But next I also want to add the relational-pouch plugin:

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

Typescript编译器将对此进行编译,但是我的浏览器出现错误:

The Typescript compiler will compile this, but I'm having errors in my browser:

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().所以我怀疑插件没有加载?

No errors in the browser, but a method from the relational-pouch is not found: setSchema(). So I suspect the plugin was not loaded?

推荐答案

OP解决方案

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

这篇关于带有Angular5/Typescript的PouchDB关系包和pouchdb查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 13:08