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

前端 未结 20 1121
时光说笑
时光说笑 2020-12-01 06:22

I am trying to map from a service call but getting an error. Looked at subscribe is not defined in angular 2? and it said that in order to subscribe we need to

20条回答
  •  粉色の甜心
    2020-12-01 06:31

    If your function is expecting to return a boolean, just do this:

    1. Import:
    import { of, Observable } from 'rxjs';
    import { map, catchError } from 'rxjs/operators';
    
    1. Then
    checkLogin(): Observable {
      return this.service.getData()
        .pipe(
          map(response => {
            this.data = response;
            this.checkservice = true;
            return true;
          }),
          catchError(error => {
            this.router.navigate(['newpage']);
            console.log(error);
            return of(false);
          })
    )}
    

提交回复
热议问题