1

I am currently getting this error:

TS2339:Property 'getCityList()' does not exist on type type of 'ServerComService'

I am injecting a service into another service. The dynamicFormDataService populates my select inputs in my html

the serverComService deals with all calls to my servers

all proper imports in the app module have been made, both services are in the providers array in the app module. Lets just be sure to state that.

The code for the dynamicFormDataService:

import {Injectable} from '@angular/core';

import 'rxjs/Rx';
import {ServerComService} from "./serverComService";

@Injectable()
export class cityGetService{

  constructor(private serverComService: ServerComService){}
  cityList= [];

  cityGet(){

    if(this.cityList.length > 0 ){
      return this.cityList;
    }
    this.cityList = ServerComService.getCityList();
    return this.cityList;
  }
}

The code for the serverComService

import {Injectable} from '@angular/core';
import {Http} from "@angular/http";

import {cityListUrl} from 'app/backendUrls';

@Injectable()
export class ServerComService{
  constructor(private http: Http){}

  getCityList(){
    value;
    this.http.get(cityListUrl)
      .subscribe(
        (response)=> value = response,
        (error)=> console.log(error)
      );
    return value;
  }
}

anything you see that I am doing wrong. Thank you my homies I baked cookies I'll mail you 2 =)

1 Answer 1

3

If getCityList() method was a static method this would've worked but in this case you need to call it like

this.cityList = this.serverComService.getCityList();
Sign up to request clarification or add additional context in comments.

2 Comments

LAMO of course I will always be haunted by the beautiful horrible this. Thank you. You want some cookies?
dm me Ill send you some!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.