最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular "scheduler.schedule is not a function" using observable - Stack Overflow

programmeradmin0浏览0评论

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')}`
发布评论

评论列表(0)

  1. 暂无评论