angular6 - 类型'void'上不存在属性'subscribe'中的angular6错误
问题描述
this._weatherService.getWeather(this.location.city,this.location.code).subscribe((response) => {
console.log(response);
this.weather = response;
});
收到此错误“消息”:“类型'void'上不存在属性'订阅'。”
解决方案
你的问题是因为你没有从getWeather()
如错误所说void
(意味着您没有返回任何东西)
所以在getWeather()
使用中return
:
getWeather(..){
...
return whatever_you_have_to_return;
}
推荐阅读
- python - 网格搜索 ValueError:估计器的参数分类器无效
- c# - C# 将数字四舍五入为 double 的任意数字
- flutter - 尝试从 API 获取数据 - 基数 10 数无效
- python - 如何将字符串列表转换为单个分隔字符串?
- django - Django - __str__ 返回非字符串(类型元组)
- asp.net-mvc - 如何将模型中的两个类的上下文传递到一个视图而不会出现此错误?
- python - 如何训练一个 CNN 回归模型,该模型接受多个输入图像并给出单个值作为输出。?
- javascript - 单击Javascript中的链接后自动返回
- python - 根据行条件过滤熊猫列
- powershell - 写主机,循环问题,如何获取摘要字符串?