Angular Error TypeError:您提供了一个无效的对象,该对象应在其中流

时间:2018-07-09 22:09:25

标签: javascript angular typescript rxjs httpclient

所以发生了一些奇怪的事情,我正在使HTTP进入我的服务,但出现错误,奇怪的是,有时它可以工作,有时不起作用,但是在过去的24小时里,它不再工作了。服务电话和订阅的代码如下。然后还有错误。

category.service.ts

 getcategory(id) {
const url = `${this.localUrl}category/${id}`;
  return this.http.get<CategoryResponse>(url)
    .pipe(
      catchError(this.errorHandler)
    )

}

错误处理程序

errorHandler(error: HttpErrorResponse) {
  if (error.error instanceof ErrorEvent) {
  // A client-side or network error occurred. Handle it accordingly.
  console.error('An error occurred:', error.error.message);
} else {
  // The backend returned an unsuccessful response code.
  console.error(
    `Backend returned code ${error.status}, ` +
    `body was: ${error.error}`);
}

    // return an observable with a user-facing error message
   return throwError(
    'Something bad happened; please try again later.');
}

add-edit-category.component.ts

if (this.router.url.indexOf('edit') >= 0) {
      this.route.paramMap.pipe(switchMap((params: ParamMap) => 
        this.categoryService.getcategory(params.get('id'))))
        .subscribe(results => {
           this.category = results.category;

          this.categoryNameControl.setValue(this.category.categoryName);
          this.categoryDescriptionControl.setValue(this.category.categoryDescription);
          console.log("I am edit", Object.keys(config))
          console.log("TEst again",this.category)
        }, error => {
            console.log("Error",error)
        });
     }

错误

Error TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
at Object.push../node_modules/rxjs/internal/util/subscribeTo.js.exports.subscribeTo (subscribeTo.js:42)
at Object.subscribeToResult (subscribeToResult.js:7)
at SwitchMapSubscriber.push../node_modules/rxjs/internal/operators/switchMap.js.SwitchMapSubscriber._innerSub (switchMap.js:103)
at SwitchMapSubscriber.push../node_modules/rxjs/internal/operators/switchMap.js.SwitchMapSubscriber._next (switchMap.js:96)
at SwitchMapSubscriber.push../node_modules/rxjs/internal/Subscriber.js.Subscriber.next (Subscriber.js:103)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (map.js:81)
at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:93)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/BehaviorSubject.js.BehaviorSubject._subscribe (BehaviorSubject.js:26)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe (Observable.js:176)
at BehaviorSubject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject._trySubscribe (Subject.js:96)

0 个答案:

没有答案