2017-07-18 69 views
0

我有一個角度應用程序,我想在PouchDB中使用PouchDBFind插件。Angular和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語句如何:

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)行,警告消失,但控制檯中的錯誤仍然存​​在。它只是說它沒有構造函數。

編輯:這是一個角度cli項目。

回答

2

您可以鎖定版本...

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

...並用以下再試一次嗎?

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

PouchDB.plugin(PouchFind); 
+0

感謝您的回答!我已更新了我的問題。而且我仍然需要像下面那樣導入: import * from'pouchdb'作爲PouchDB。從'pouchdb'導入PouchDB表示沒有默認導出 – Lados

+0

卸載類型並重新安裝pouchdb和pouchdb-find後,我可以按照您的建議和所有工作來導入它。謝謝! – Lados

+0

Okey,對不起,我犯了一個錯誤。導入工作,但我仍然得到這個錯誤:錯誤TypeError:__WEBPACK_IMPORTED_MODULE_1_pouchdb__不是一個構造函數 – Lados