ОШИБКА Ошибка: Uncaught (в обещании): TypeError: Promise.resolve не является функцией TypeError: Promise.resolve не является функцией - PullRequest
0 голосов
/ 03 февраля 2020

Я новичок в ioni c 4, когда я звоню в мою службу, у меня появляется эта ошибка

Ошибка: ошибка (в обещании): ошибка типа: Promise.resolve не является Функция TypeError: 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() Метод Я получил следующую ошибку:

Ошибка: Uncaught (в обещании): TypeError: Promise.resolve не является функцией TypeError: Promise.resolve не является функцией

1 Ответ

0 голосов
/ 03 февраля 2020

Вам нужно пометить функцию как asyn c и вернуть обещание правильного типа.

async findAllRelationalDocByType(type) : Promise<*insert type here*>{
        return this.localDB.rel.find(type);
      }

, а затем пометить вызов как asyn c и дождаться результата

async getAll(){
    await this.pouchdbService.findAllRelationalDocByType(this.type)
    .then((data) => {
      console.log(data);
    }).catch((err) => {
      console.log(err);
    }); 
  }
}

Надеюсь, это поможет

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...