admin管理员组

文章数量:1420929

I'm having an issue with an observable :

In a service I have a function (in editponent):

public patchOne(entity: Tier): Observable<any> {

    const userData: any = this.httpService.getDataFromLocalStorage(AuthService.LOCAL_STORAGE_USER_TAG);

    return this.httpService.patch(`/someurl/${entity.uid}`, {
      params: {
        user_uid: JSON.parse(userData).userUId,
      },
      body: entity.createPatchTier(),
    }).map((res: any) => {
      // TODO : to plete
      return {};
    }).catch((error: any) => Observable.throw('patchOne - ', error.json().errorMessage || 'Server error'));
  }

Calling it from ponent (in editponent):

  onSave() {
    if (this.validateFormData()) {
      this.tierService.patchOne(this._item).subscribe(() => {
        this.appCommunicationService.valid('Success');
      }, (error: any) => {
        this.appCommunicationService.error(error.message);
      });
    } else {
      this.appCommunicationService.info('Fail');
    }
  }

Triggered from a button with this property (ViewComponent.html):

(click)="ponent.onSave()"

I'm having this error uppon clicking :

ERROR TypeError: scheduler.schedule is not a function
    at ErrorObservable.webpackJsonp.../../../../rxjs/observable/ErrorObservable.js.ErrorObservable._subscribe (ErrorObservable.js:72)
[...]
webpackJsonp.../../../../../src/app/ponents/edit/editponent.ts.EditTiersComponent.onSave @   editponent.ts:99
(anonymous) @   ViewComponent.html:14

Any idea ?

I'm having an issue with an observable :

In a service I have a function (in edit.ponent):

public patchOne(entity: Tier): Observable<any> {

    const userData: any = this.httpService.getDataFromLocalStorage(AuthService.LOCAL_STORAGE_USER_TAG);

    return this.httpService.patch(`/someurl/${entity.uid}`, {
      params: {
        user_uid: JSON.parse(userData).userUId,
      },
      body: entity.createPatchTier(),
    }).map((res: any) => {
      // TODO : to plete
      return {};
    }).catch((error: any) => Observable.throw('patchOne - ', error.json().errorMessage || 'Server error'));
  }

Calling it from ponent (in edit.ponent):

  onSave() {
    if (this.validateFormData()) {
      this.tierService.patchOne(this._item).subscribe(() => {
        this.appCommunicationService.valid('Success');
      }, (error: any) => {
        this.appCommunicationService.error(error.message);
      });
    } else {
      this.appCommunicationService.info('Fail');
    }
  }

Triggered from a button with this property (ViewComponent.html):

(click)="ponent.onSave()"

I'm having this error uppon clicking :

ERROR TypeError: scheduler.schedule is not a function
    at ErrorObservable.webpackJsonp.../../../../rxjs/observable/ErrorObservable.js.ErrorObservable._subscribe (ErrorObservable.js:72)
[...]
webpackJsonp.../../../../../src/app/ponents/edit/edit.ponent.ts.EditTiersComponent.onSave @   edit.ponent.ts:99
(anonymous) @   ViewComponent.html:14

Any idea ?

Share Improve this question edited Dec 12, 2017 at 13:10 An-droid asked Dec 12, 2017 at 12:56 An-droidAn-droid 6,48510 gold badges51 silver badges95 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Looks like you have an error on this line:

.catch((error: any) => Observable.throw('patchOne - ', error.json().errorMessage || 'Server error'));

The Observable.throw has the following signature:

public static throw(error: any, scheduler: Scheduler): Observable

As you can see, the 2nd parameter is the scheduler. In your code, you're providing this 2nd parameter, so ultimately RxJs is trying to invoke schedule on your string (error.json().errorMessage || 'Server error').

You need to update your error message to use string concatenation. e.g.:

'patchOne - ' + (error.json().errorMessage || 'Server error'))

Or perhaps using string interpolation:

`patchOne - ${(error.json().errorMessage || 'Server error')}`

本文标签: javascriptAngular quotschedulerschedule is not a functionquot using observableStack Overflow