Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度错误TypeError:您提供了一个无效的对象,其中需要一个流_Javascript_Angular_Typescript_Rxjs_Httpclient - Fatal编程技术网

Javascript 角度错误TypeError:您提供了一个无效的对象,其中需要一个流

Javascript 角度错误TypeError:您提供了一个无效的对象,其中需要一个流,javascript,angular,typescript,rxjs,httpclient,Javascript,Angular,Typescript,Rxjs,Httpclient,所以有些奇怪的事情发生了,我在我的服务中做了一个HTTP get,但是我得到了一个错误,奇怪的是它有时工作,有时不工作,但是在过去的24小时里它不再工作了。服务呼叫和订阅的代码如下所示。然后是错误 类别.服务.ts getcategory(id) { const url = `${this.localUrl}category/${id}`; return this.http.get<CategoryResponse>(url) .pipe( catch

所以有些奇怪的事情发生了,我在我的服务中做了一个HTTP get,但是我得到了一个错误,奇怪的是它有时工作,有时不工作,但是在过去的24小时里它不再工作了。服务呼叫和订阅的代码如下所示。然后是错误

类别.服务.ts

getcategory(id) {
    const url = `${this.localUrl}category/${id}`;
    return this.http.get<CategoryResponse>(url)
        .pipe( catchError(this.errorHandler) );
}
添加-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)
        });
}
错误


你能展示一下这个.errorHandler的功能吗?@Mium我已经添加了错误处理程序你的问题还没有解决吗?嘿,伙计们,我找到了问题的解决方案,我导入了错误的RXJ。我应该发布答案还是不可撤销,因为这只是一个很小的导入问题,这取决于错误。这是可能系统地发生在其他人身上的事情吗?如果没有,我认为最好删除这个问题。
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)