如何解决“错误:您在期望流的位置提供了'undefined'。您可以提供Observable,Promise,Array或Iterable”?

时间:2019-02-08 06:51:32

标签: angular loopbackjs

我正在使用角度材质表,因为分页不仅在服务器中起作用,而且在本地也能正常工作。在服务器中,当我打开包含表的页面时,数据被推送到表中,但分页不起作用并且弹出错误

ERROR TypeError: You provided 'undefined' where a stream was expected.
You can provide an Observable, Promise, Array, or Iterable.
    at subscribeTo (subscribeTo.js:41)
    at subscribeToResult (subscribeToResult.js:11)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._innerSub
(mergeMap.js:74)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._tryNext
(mergeMap.js:68)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapSubscriber._next
(mergeMap.js:51)
    at MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next
(Subscriber.js:53)
    at Observable._subscribe (subscribeToArray.js:5)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable._trySubscribe
(Observable.js:43)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.subscribe
(Observable.js:29)
    at MergeMapOperator.push../node_modules/rxjs/_esm5/internal/operators/mergeMap.js.MergeMapOperator.call
(mergeMap.js:29)

Component.ts

getCustomerinfoList(): void {
    this.adminService.getCustomerinfoList(this.componentName, this.selectedCustomer.customer_id)
      .subscribe(customerlist => {
        let c_rates = customerlist[0][0].customer_routes;
        this.customers = customerlist;
        this.cust_specificData = c_rates ? JSON.parse(c_rates) : [];
        this.cInfo_dataSource.data = this.cust_specificData
        this.cInfo_dataSource.paginator = this.Routepaginator;
        this.cInfo_dataSource.sort = this.Routesort;
      }
  }

service.ts

getCustomerinfoList(actionComponentName: String, customerid: number) {
    const url = `${this.baseURL + actionComponentName}/getCustomerRateAccessories?customer_id=${customerid}&access_token=${this.authService.getAuthToken()}`;
    return this.http.get<any>(url, this.httpOptions)
  }

Interceptor.ts

import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpResponse } from '@angular/common/http';

import { Observable } from 'rxjs/Rx';
import 'rxjs/add/observable/throw'
import { tap, catchError } from 'rxjs/operators';


@Injectable()

export class loadingInterceptor implements HttpInterceptor {

  intercept(req: any, next: HttpHandler): Observable<HttpEvent<any>> {

    let loadingContainer: HTMLElement = document.getElementsByClassName('bg-pre-loader').item(0) as HTMLElement

    loadingContainer.style.display = 'flex';

    return next.handle(req).pipe(
      tap(event => {
        if (event instanceof HttpResponse) {
          loadingContainer.style.display = 'none';
        }
      }), catchError((err) => {
        loadingContainer.style.display = 'none';
        return Observable.throw(err);
      })
    )
  }
}

我希望数据能够推送到表中,并且数据应该能够分页

注意: 该代码在本地工作正常, 仅在服务器上无法正常工作

1 个答案:

答案 0 :(得分:1)

实际上是物料表分页器中的错误,该错误已被删除后得到解决

谢谢大家