Service code
private posts: Post[] = [];
private postsupdated = new Subject<Post[]>();
getPost() {
return [...this.posts]
}
getPostsUpdatedListener() {
return this.postsupdated.asObservable()
}
addPosts(title: String, content: String) {
const post: Post = { title: title, content: content }
this.posts.push(post)
this.postsupdated.next([...this.posts])
}
constructor() { }
component code
Posts: Post[] = [];
private postsSub = Subscription;
ngOnInit(): void {
this.Posts = this.postService.getPost();
this.postsSub = this.postService.getPostsUpdatedListener()
.subscribe((posts: Post[]) => {
this.Posts = posts
})
}
ngOnDestroy() {
this.postsSub.unsubscribe();
}
Type 'Subscription' is missing the following properties from type 'typeof Subscription': prototype, EMPTY and Property 'unsubscribe' does not exist on type 'typeof Subscription'.how to resolve it???