Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting some issues using {return this.getAll.get(this.url)} when consuming an API in Angular

I am trying to consume an API using Angular and Typescript, my previous knowledge in using API’s is mainly in Javascript so I am pretty new to it, however what I have so far is giving me an issue:

I created a new service file:

growth-service.ts

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class GrowthService {

  url = 'https://uks-tst-tbp-gw.azurewebsites.net/business/getcategories'
  constructor(private http:HttpClient) { }

  getAllOptions(): any{
    return this.getAllOptions.get(this.url)
  }
}

but the line return this.getAllOptions.get(this.url) is showing me an error on .get saying that

TS2339: Property ‘get’ does not exist on type

However I cannot find a reason as to why?

>Solution :

You are calling getAllOptions from the function getAllOptions()itself

probably what you want to do is:

getAllOptions(): Observable<any>{
  return this.http.get(this.url)
}

also as a naming convention you should call function that returns an Observable with a dollar sign at the end i.e. getAllOptions$(){}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading