angular-pouchdb: pouchDB 未定义或不是函数
angular-pouchdb: pouchDB is not defined or is not a function
我已经在我的 angular 应用程序中安装了这个库:https://github.com/angular-pouchdb/angular-pouchdb(使用 ionic add angular-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 中的工厂,使数据库在应用程序中随处可用:
.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;
}])
index.html 中的脚本调用:
<script src="lib/angular-pouchdb/angular-pouchdb.js"></script>
注意:如果我改写 .factory('usersDatabase', [ function(pouchDB) {
(大写 DB 而不是小写 db),
我收到此错误:Uncaught TypeError: pouchDB is not a function
.
请检查错字 pouchDB -> pouchdb
.factory('usersDatabase', [ function(pouchdb) {
var usersDatabase = pouchDB('boardline_users');
Angular-pouchdb依赖于pouchdb,所以index.html中需要这一行:
<script src="lib/pouchdb/dist/pouchdb.min.js"></script>
我已经在我的 angular 应用程序中安装了这个库:https://github.com/angular-pouchdb/angular-pouchdb(使用 ionic add angular-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 中的工厂,使数据库在应用程序中随处可用:
.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;
}])
index.html 中的脚本调用:
<script src="lib/angular-pouchdb/angular-pouchdb.js"></script>
注意:如果我改写 .factory('usersDatabase', [ function(pouchDB) {
(大写 DB 而不是小写 db),
我收到此错误:Uncaught TypeError: pouchDB is not a function
.
请检查错字 pouchDB -> pouchdb
.factory('usersDatabase', [ function(pouchdb) { var usersDatabase = pouchDB('boardline_users');
Angular-pouchdb依赖于pouchdb,所以index.html中需要这一行:
<script src="lib/pouchdb/dist/pouchdb.min.js"></script>