我目前收到此错误:
TS2339:Property 'getCityList()' does not exist on type type of 'ServerComService'
我正在将服务注入其他服务。 dynamicFormDataService
填充我的html中的选择输入
serverComService
处理对我服务器的所有调用
已在app模块中进行了所有正确导入,两个服务都位于app模块的providers数组中。让我们一定要说明。
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;
}
}
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;
}
}
你看到我做错了什么。谢谢我的兄弟们,我烤饼干,我会邮寄给你2 =)
答案 0 :(得分:2)
如果getCityList()
方法是static
方法,这可能会有效,但在这种情况下,您需要将其称为
this.cityList = this.serverComService.getCityList();