我已经在我的角度应用程序中安装了此库:https://github.com/angular-pouchdb/angular-pouchdb(使用ionic add angular-pouchdb
)。angular-pouchdb:pouchDB未定义或不是函数
但我得到这个错误:Uncaught ReferenceError: pouchDB is not defined
当我试图声明一个工厂,实例化数据库。看到我的代码如下。
模块注射app.js:
angular.module('BoardLine', ['ionic', 'ngCookies', 'ui.unique', 'pouchdb', 'BoardLine.controllers', 'BoardLine.services', 'BoardLine.filters'])
厂services.js使现有的数据库无处不在的应用程序:index.html中
.factory('usersDatabase', [ function(pouchdb) {
var usersDatabase = pouchDB('boardline_users');
var remote = 'https://louisromain:bingin/*@louisromain.cloudant.com/boardline_users';
var opts = {live: true,
retry: true};
usersDatabase.replicate.to(remote, opts);
usersDatabase.replicate.from(remote, opts);
//console.log(usersDatabase);
return usersDatabase;
}])
Srcipt电话:
<script src="lib/angular-pouchdb/angular-pouchdb.js"></script>
注意:如果我改为写.factory('usersDatabase', [ function(pouchDB) {
(大写的DB而不是小写的db), 我收到此错误:Uncaught TypeError: pouchDB is not a function
。
感谢,我把这个'.factory( 'userDatabase',[function(pouchDB){...'now,而且我有一个新错误:'Uncaught TypeError:pouchDB不是一个函数' – Louis
不客气,Angular模块的名字是“pouchdb”,(而不是puchDB)你应该使用angular-pouchdb.js中定义的确切名称。同时确保模块代码被加载你的Angular脚本。 – emir
对不起,但我没有看到我在没有“o”的情况下输入错字“puchdb”的位置......我在上面的问题中搜索了我的代码,并且我没有输入这个错字 – Louis