这是问题:我有一个服务在构造函数中发出HTTP请求:
constructor(public http: Http, public geolocation: Geolocation) {
this.http = http;
this.geolocation = geolocation;
//Http request... this will set variable forecast of the class when complete.
this.getForecast(16);
}
然后我在这样的组件中注入该服务:
constructor(public connector: ApiConnector) {
this.forecast = connector.forecast;
}
如果我尝试在组件装饰器上使用组件类的预测成员,就像我在这里一样:
@Component({
selector: 'app',
directives: [MainForecast, DailyForecast],
template: `
`,
})
我收到一个错误,"无法读取未定义的属性'列表'......"
是否有可能在组件构造函数中使用promises?