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

I'm having an issue with an observable : In a service I have a function (in editponent): public pa

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')}`

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745320675a4622429.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信