EIDT:这个问题是一个Angular2问题,应该在下一个区域解决。js更新。有关临时修复,请参阅:
https://github.com/angular/zone.js/issues/886
然后回答。
为了从我的Angular2应用程序中访问pouchDB,我编写了一个javascript界面:
var db;
var remoteDb;
function LocalDb() {
db = new PouchDB('test', {storage:'persistent'});
};
function RemoteDb(url) {
remoteDb = new PouchDB(url);
};
function sync() {
db.sync(remoteDb);
};
function addTest() {
var test = {
title: 'ABC',
completed: false
};
db.post(test);
};
为了可读性,我删除了所有回调。我通过运行
npm install pouchdb
<script src="../node_modules/pouchdb/dist/pouchdb.min.js"></script>
索引。html。
<script src="assets/dist/pouchdb.min.js"></script>
如果我按get-localdb和get-remotedb按钮,一切都会正常。在我按下同步按钮的那一刻,我得到了很多
wrapFn@http://localhost:4200/polyfills.bundle.js:3614:1
firefox上的递归错误太多。Chrome告诉我超过了最大调用堆栈大小。
任何帮助都将不胜感激。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>RemoteCouch</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<h3>Hello World</h3>
<script type="text/javascript" src="PATH/pouchdb.min.js"></script>
<script>
var db = new PouchDB('new');
db.post({
name: 'David',
age: 69
});
db.changes().on('change', function() {
console.log('Ch-Ch-Changes');
});
db.replicate.to('http://10.20.20.37:5984/new');
</script>
</body>
</html>
我用tapio/live服务器托管了这个文件,它可以正常工作。这可能是角度问题,或者我做错了什么。
只是为了再试一次,我做了一个新项目,添加了如下所述的数据库
https://github.com/nolanlawson/pouchdb-find/issues/201
并在纯typescript中进行了相同的测试,但意外的是,错误仍然存在。