我不断收到“类型为void的属性订阅不存在”的错误

问题描述

这是我的ts文件函数,会引发错误

post-list.componenet.ts

operator()

这是服务文件



ngOnInit() {
  this.posts = this.postsService.getPosts();
  this.postsSub = this.postsService.getPostUpdateListener()
    .subscribe((posts: Post[]) => {
      this.posts = posts});
}


}



我已经导入了'rxjs'依赖模块,我似乎无法确定如何纠正错误代码在浏览器上运行,但是我没有得到想要的输出

解决方法

别忘了在getPostUpdateListener()上返回数据

<style>
  .small {
    font-size: 12px;
  }
  .link {
    text-decoration: underline;d
  }
  .headline {
    font-size: 18px;
  }
</style>