首页 > 解决方案 > 类型'void'上不存在属性'subscribe'中的angular6错误

问题描述

this._weatherService.getWeather(this.location.city,this.location.code).subscribe((response) => {
     console.log(response);
     this.weather = response;
   });

收到此错误“消息”:“类型'void'上不存在属性'订阅'。”

标签: angular6

解决方案


你的问题是因为你没有getWeather()

如错误所说void(意味着您没有返回任何东西)

所以在getWeather()使用中return

getWeather(..){
...
return whatever_you_have_to_return;
}

推荐阅读