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

前端 未结 20 1196
时光说笑
时光说笑 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:44

    I wrote this because I arrive here searching for the same error, and this could be useful for someone in the future.

    I get the same error while trying to initialize a service variable from its constructor making a call to a remote API trough http.get and .subscribe()

    After many tests without understanding what the problem was, i finally get it: My application had authentication and an HttpInterceptor, and i was trying to initialize the service calling a public API method using http.get(...) without 'No-Auth' headers. I added them like here, and problem solved for me:

    getData() {
    var reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-urlencoded','No-Auth':'True' });    
    return this.http.get(environment.urlApi.Literales, { headers: reqHeader });  
    }
    

    What a headache :(

提交回复
热议问题