TypeError: недопустимый объект, где ожидался поток, после переключения на Angular 6 и RxJS 6 - PullRequest
0 голосов
/ 07 июня 2018

после перехода на Angular 6 мои асинхронные валидаторы больше не работают.Я использую такой подход, чтобы отклонить запросы: https://github.com/angular/angular/issues/6895#issuecomment-329464982

Мой код выглядит так:

    // in register component
validateNicknameNotTaken(control: AbstractControl): Observable<any> {
    return timer(600)
      .pipe(
        switchMapTo(this.service.isNicknameNotTaken(control.value)),
        map(res => {
          return res ? null : {nicknameTaken: true};
        }),
        take(1)
      );
  }

ngOnInit() {
//...
nickname: ['', [Validators.required, Validators.maxLength(20)], this.validateNicknameNotTaken.bind(this)]
//...
}

// in service
isNicknameNotTaken(nickname: string): Observable<boolean> {
    return this.apollo
      .use('public')
      .query<{ isNicknameNotTaken: boolean }>({
        query: isNicknameNotTakenQuery,
        variables: {
          nickname: nickname
        },
        fetchPolicy: 'no-cache'
      })
      .pipe(
        map(result => result.data.isNicknameNotTaken)
      );
  }

Но я получаю следующую ошибку:

TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Это полный журнал:

    core.js:1598 ERROR TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at subscribeTo (subscribeTo.js:41)
    at subscribeToResult (subscribeToResult.js:6)
    at new ForkJoinSubscriber (forkJoin.js:154)
    at Observable._subscribe (forkJoin.js:135)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:176)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:161)
    at MapOperator.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapOperator.call (map.js:51)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe (Observable.js:158)
    at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator (forms.js:2637)
    at FormControl.push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity (forms.js:2606)
defaultErrorLogger @ core.js:1598
push../node_modules/@angular/core/fesm5/core.js.ErrorHandler.handleError @ core.js:1647
next @ core.js:4727
schedulerFn @ core.js:3712
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:253
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next @ Subscriber.js:191
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next @ Subscriber.js:129
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next @ Subscriber.js:93
push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next @ Subject.js:53
push../node_modules/@angular/core/fesm5/core.js.EventEmitter.emit @ core.js:3704
(anonymous) @ core.js:4084
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:388
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:138
push../node_modules/@angular/core/fesm5/core.js.NgZone.runOutsideAngular @ core.js:4021
onHandleError @ core.js:4084
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.handleError @ zone.js:392
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:191
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:496
ZoneTask.invoke @ zone.js:485
timer @ zone.js:2054
setTimeout (async)
scheduleTask @ zone.js:2075
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:407
onScheduleTask @ zone.js:297
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:401
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:232
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMacroTask @ zone.js:255
scheduleMacroTaskWithCurrentZone @ zone.js:1114
(anonymous) @ zone.js:2090
proto.(anonymous function) @ zone.js:1394
hostReportError @ hostReportError.js:8
push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.error @ Subscriber.js:225
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error @ Subscriber.js:132
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error @ Subscriber.js:106
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._error @ Subscriber.js:132
push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error @ Subscriber.js:106
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe @ Observable.js:183
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:161
push../node_modules/rxjs/_esm5/internal/operators/map.js.MapOperator.call @ map.js:51
push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe @ Observable.js:158
push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl._runAsyncValidator @ forms.js:2637
push../node_modules/@angular/forms/fesm5/forms.js.AbstractControl.updateValueAndValidity @ forms.js:2606
push../node_modules/@angular/forms/fesm5/forms.js.FormControl.setValue @ forms.js:3044
updateControl @ forms.js:1765
(anonymous) @ forms.js:1750
push../node_modules/@angular/forms/fesm5/forms.js.DefaultValueAccessor._handleInput @ forms.js:784
(anonymous) @ RegisterComponent.html:30
handleEvent @ core.js:11107
callWithDebugContext @ core.js:12204
debugHandleEvent @ core.js:11907
dispatchEvent @ core.js:8561
(anonymous) @ core.js:9005
(anonymous) @ platform-browser.js:1215
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:421
onInvokeTask @ core.js:4053
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:420
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:188
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:496
invokeTask @ zone.js:1540
globalZoneAwareCallback @ zone.js:1566

Если я что-то используюВот как это работает:

return this.service
  .isNicknameNotTaken(control.value)
  .pipe(
    map(res => {
      return res ? null : {nicknameTaken: true};
    }),
  );

Я перенес все приложение, нет rxjs-compat.

Есть предложения или советы, что искать?

С уважением,Керстен

...