Problem in Calling a function in Provider constructor. Why?

Dear Friends,

I am using ionic3, provider for take data from a sample service mentioned in tutorial: Ionic 3 Consuming REST API using New Angular 4.3 HttpClient

I set all details to take data from web service as I mention. But in ‘property.ts’ , when call the method for take data I got error as

Cannot find name ‘getUsers’. Did you mean the instance member ‘this.getUsers’?

I added the vscode editor preview below .

Please advise what I am wrong with

Waiting fast reply



You have declared your method in your constructor, should be outside of it

export class Property {

  constructor() {
    // not here
   getUsers() { ...
  // but here
  getUsers {
1 Like

As @reedrichards said you dont declare functions in a constructor.
Please do it like this:

export class PropertyProvider {
 apiUrl:string = "YourUrl"; 

 constructor(private http: HttpClient) { }
   //Your get Users Function