我想转换为Angular 2(Ionic2),我的应用程序使用pouchDB。
在Angular1中,我使用的是带有小写pouchDB的var _usersDatabase = pouchDB(CouchConstants.COUCHDB_USERS_DB_NAME);
而没有使用new
。但是TypeScript编译器在抱怨,所以我做到了:
import { Injectable } from '@angular/core';
import { LocalStorageService } from 'angular-2-local-storage';
import { UtilsService } from '../providers/utils-service';
import { MigrationService } from '../providers/migration-service';
import { CouchConstants } from '../couch-constants';
import PouchDB from 'pouchdb';
@Injectable()
export class UsersDatabase {
constructor(
private storageService: LocalStorageService
, private UtilsService: UtilsService
, private MigrationService: MigrationService
) {
'use strict';
var _usersDatabase = new PouchDB(CouchConstants.COUCHDB_USERS_DB_NAME);
//We attach the function if necessary
if (_usersDatabase.updateReplication == null) {
_usersDatabase.updateReplication = function (newDocsIds) {
console.info("Updating replications with: ");
console.info(newDocsIds);
...
但我得到这个错误:
Typescript Error
Property 'updateReplication' does not exist on type 'Database<{}>'.
src/providers/users-database.ts
//We attach the function if necessary
if (_usersDatabase.updateReplication == null) {
要在TypeScript项目中导入PouchDB,您需要执行以下操作:
// Correct
import * as PouchDB from 'pouchdb';
而不是:
// Incorrect
import PouchDB from 'pouchdb';
此外,我不相信updateReplication
是一个受支持的PouchDB API,这可能是你看到TypeScript警告的原因。
我刚刚使用angular-cli安装了PouchDB For Angular 2 + Typescript。这就是我所做的,它对我有用:
ng new SOMENAME
npm install --save pouchdb
npm install --save-dev @types/pouchdb
import PouchDB from 'pouchdb';
public db: any;
和init this.db = new PouchDB('test'); // , {storage:'persistent'} not working in typescript without updating typings
中见https://github.com/nolanlawson/pouchdb-find/issues/201。
如果您在使用EPERM错误的Windows上安装软件包时遇到问题,请使用(f.e.)npm install --save pouchdb --no-optional
来禁用警告。安装应该还可以。有关更多信息,请参阅https://github.com/npm/npm/issues/17671