这里的职能范围内的服务是我如何我的组件之一内获得四方信息的例子:使用角2级组件
import {Component} from 'angular2/core';
import {FoursquareService} from '../../services/foursquare'
@Component({
templateUrl : 'app/components/new-listing/new-listing.html',
providers : [FoursquareService]
})
export class NewListingComponent {
venues : Array<Object> = [];
constructor(foursquareApi : FoursquareService) {
//Foursquare api
foursquareApi.foursquareGet('&ll=51.5255168,-0.0858669&query=xoyo')
.subscribe(data => {
this.venues = data.response.venues;
console.log(this.venues);
});
}
}
这会将相关对象在网页加载安慰,但是我想在点击一个按钮或用户输入时实现相同的功能,因此在单独的功能中使用它,但是每次从构造函数中删除foursquareApi : FoursquareService
时,都会出现各种错误。