【发布时间】:2020-05-19 01:31:49
【问题描述】:
我是 ionic 4 的初学者,当我调用我的服务时出现此错误
ERROR Error: Uncaught (in promise): TypeError: Promise.resolve is not 函数类型错误:Promise.resolve 不是函数
我的服务:
import { Injectable } from '@angular/core';
import PouchDB from 'pouchdb';
import PouchdbFind from 'pouchdb-find';
import RelationalPouch from 'relational-pouch';
@Injectable({
providedIn: 'root'
})
export class PouchdbService {
public remoteDB: any;
public localDB: any;
constructor() {
PouchDB.plugin(RelationalPouch);
PouchDB.plugin(PouchdbFind);
this.localDB = new PouchDB('couture');
this.createDBSchema();
}
public createRelationalDoc(doc){
return this.localDB.rel.save(doc.type, doc);
}
public updateRelationalDoc(doc){
return this.localDB.rel.save(doc.type, doc);
}
public deleteRelationalDocDefinitivement(doc){
return this.localDB.rel.del(doc.type, doc);
}
public findRelationalDocByID(type, id){
return this.localDB.rel.find(type,id);
}
public findRelationalDocByTypeAndID(type, id){
return this.localDB.rel.find(type,id);
}
public existRelationalDocByTypeAndID(type, id){
return this.localDB.rel.find(type,id).then((res) => {
return true
}).catch((err) => {
return false;
});
}
public findAllRelationalDocByType(type){
return this.localDB.rel.find(type);
}
public findRelationalDocByTypeAndOptions(type, options){
return this.localDB.rel.find(type, options);
}
public findRelationalDocHasMany(type, belongsToKey, belongsToId){
return this.localDB.rel.findHasMany(type, belongsToKey, belongsToId);
}
createDBSchema(){
this.localDB.setSchema([
{
singular: 'client',
plural: 'clients',
relations: {
'user': {belongsTo: 'user'}
}
},
{
singular: 'tache',
plural: 'taches',
relations: {
'client': {belongsTo: 'client'},
'user': {belongsTo: 'user'}
}
},
{
singular: 'user',
plural: 'users'
}
]);
}
还有我的页面:
import { PouchdbService } from 'src/app/services/pouchdb.service';
@Component({
selector: 'app-user',
templateUrl: 'user.page.html',
styleUrls: ['user.page.scss']
})
export class UserPage {
public header:string;
public user:any;
public users:any;
public type:any="user";
constructor( private pouchdbService:PouchdbService) {
this.getAll();
}
ngOnInit() {
}
ionViewWillEnter(){
}
getAll(){
this.pouchdbService.findAllRelationalDocByType(this.type)
.then((data) => {
console.log(data);
}).catch((err) => {
console.log(err);
});
}
}
当我调用getAll() 方法时出现以下错误:
Error: Uncaught (in promise): TypeError: Promise.resolve is not a function TypeError: Promise.resolve 不是函数
【问题讨论】:
标签: javascript angular promise ionic4