【发布时间】:2020-08-05 20:52:46
【问题描述】:
我在 IONIC 5 中有这项服务:
import { HttpClient } from '@angular/common/http';
.
.
.
getPlaces(placeId: string) {
return this.httpClient.get(
`https://test.com/offered-place/${placeId}.json`)
}
.
.
.
在我的组件中,当我尝试调用 may 服务的功能并订阅它时:
this.myService.getPlaces().subscribe(()=>{})...
我收到错误:TypeError: Cannot read property 'subscribe' of undefined.
但是当我尝试在服务中订阅时它可以工作!!
ps:
- 离子 5
我的服务被注入到我的组件的构造函数中(我得到了我的错误)
我的服务被注释了:
@Injectable({ 提供在:“根” })
- IDE 可视化代码
提前致谢
【问题讨论】:
标签: angular ionic-framework observable angular8 ionic5