TypeError: Sie bereitgestellt, 'undefined', wobei ein stream zu erwarten war

Ich habe eine Ionische Anwendung, die eine user Anbieter mit einem signup() Methode:

doSignup() {
  //set login to same as email
  this.account.login = this.account.email;
  //Attempt to login in through our User service
  this.user.signup(this.account).subscribe((resp) => {
    this.navCtrl.push(MainPage);
  }, (err) => {
    //console.log('error in signup', err);
    //^^ results in 'You provided 'undefined' where a stream was expected'
    //this.navCtrl.push(MainPage);

    //Unable to sign up
    let toast = this.toastCtrl.create({
      message: this.signupErrorString,
      duration: 3000,
      position: 'top'
    });
    toast.present();
  });
}

Aus irgendeinem Grund, dieser code ruft nie den Erfolg-Rückruf, wird nur der Fehler-handler. Wenn Sie es tut, wird es die Ergebnisse in der Fehlermeldung, die Sie sehen in den Kommentar oben.

Meine user.signup() Methode sieht wie folgt aus:

signup(accountInfo: any) {
  return this.api.post('register', accountInfo).share();
}

Meine Api - Klasse sieht wie folgt aus:

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';

/**
 * Api is a generic REST Api handler. Set your API url first.
 */
@Injectable()
export class Api {
  public static API_URL: string = 'http://localhost:8080/api';

  constructor(public http: HttpClient) {
  }

  get(endpoint: string, params?: any, reqOpts?: any) {
    if (!reqOpts) {
      reqOpts = {
        params: new HttpParams()
      };
    }

    //Support easy query params for GET requests
    if (params) {
      reqOpts.params = new HttpParams();
      for (let k in params) {
        reqOpts.params.set(k, params[k]);
      }
    }

    return this.http.get(Api.API_URL + '/' + endpoint, reqOpts);
  }

  post(endpoint: string, body: any, reqOpts?: any) {
    return this.http.post(Api.API_URL + '/' + endpoint, body, reqOpts);
  }

  put(endpoint: string, body: any, reqOpts?: any) {
    return this.http.put(Api.API_URL + '/' + endpoint, body, reqOpts);
  }

  delete(endpoint: string, reqOpts?: any) {
    return this.http.delete(Api.API_URL + '/' + endpoint, reqOpts);
  }

  patch(endpoint: string, body: any, reqOpts?: any) {
    return this.http.put(Api.API_URL + '/' + endpoint, body, reqOpts);
  }
}

Ich habe versucht, das entfernen share() aus user.signup() Rückkehr Observable<any>, aber das hilft nicht.

Wo sind Sie, rufen Sie doSignup() ? Vielleicht ist 'dieses' ist nicht verfügbar in diesem Kontext.
Es heißt von <form (submit)="doSignup()"> in meinem signup.html: github.com/oktadeveloper/ionic-jhipster-starter/blob/master/src/.... eine Anmeldung.ts ist hier: github.com/oktadeveloper/ionic-jhipster-starter/blob/master/src/...

InformationsquelleAutor Matt Raible | 2017-12-16

Schreibe einen Kommentar