为什么我的Ng2服务不能在函数中使用我的类变量?

时间:2016-10-29 02:14:42

标签: angular typescript

我假设这个答案非常简单,但我有一个公共变量listSports我通过MapService将sports传递给我的组件。

我还希望将它传递给公共函数getMapData,该函数将Http get Observable返回给组件,但我似乎无法这样做?

@Injectable()
export class MapService {

  // list of sports to export
  listSports: string[] = ["baseball", "football", "paddle", "soccer", "boxing", "golf", "hockey",
    "tennis", "volleyball", "skateboard", "kickball", "bowling", "pool", "offroad",
    "running", "hiking", "skating", "dance", "hockey", "yoga", "wrestling", "squash", "swimming", "horseriding", "fishing",
    "handball", "sailing", "shooting", "bike", "hunting", 'archery', 'karting', 'atv', "karting", "kayaking", 'climbing',
    'cricket', 'motorcycle', 'rugby', 'judo', 'scuba', 'barre', 'atv', 'basketball', 'rowing', 'karate', 'mma', 'equestrian', 'gymnastics'
  ];

  constructor(private http: Http) { }
  //return event map data from server
  getMapData(chosen?: string[]): Observable<marker.MapMarker[]> {

在这里失败,并没有传入this.listSports变量

    let sportChoices: string[] = chosen !== undefined ? chosen : this.listSports;

    // returns all we need to to make google map markers and populate out menus
    return this.http.get('http://localhost:4000/api/events')
      .map((result) => { ....

继续直到结束

0 个答案:

没有答案