Property subscribe does not exist on type '(term:string) => Observable<any>'

I get the data from my server like so :slight_smile:

  private allData(input:string): Observable<any> {
        let params = new HttpParams().set('q', input);
        return this.httpClient.get(Configuration.getData(url), { params: params });
    }

    public getDataService(){
        return this.dataService = (term: string) => this.allData(term);
    }

and in my controller, i would like to check the status of the request above to execute a specific UI action. Here is how i subscribe my data:

this.getDataService().subscribe(
      res => this.httpData = res.results,
      err => console.warn(err),
      () => {
        this.loading.dismiss() /*close loader*/
      }
  )

I have this error :“Property subscribe does not exist on type ‘(term:string) => Observable’”

Any help :slight_smile: ?

Doesn’t the error point out this piece of code maybe?

Are you using Ionic 1 or >= 2? You are speaking of controller, which kind of goes with 1 but you posted your question in >= 2…

I >= 2, because I don’t know 1, could you maybe display the all code of your provider? or does this piece of code find place directly in your component/page?

Your call to getDataServices requires and argument as per your own definition (term).

Not sure why you need a function that returns a function or maybe even worse: the result of you setting this.Dataservicr to something (which always resolves to true, not a function. And true does not have a subscribe method). So to be short: your code seems quite ambiguous to read/interpret unless you are very sure what u r doinh