I'm trying to understand best practice in using ngDestroy or unsubscribe when calling an angular service. With the example below, can someone show me how you would properly use ngDestroy in this situation?
this.submitPostService.getUserName(this.userId).subscribe(user => {
console.log("THIS IS THE USER!");
console.log(user);
this.username = user.posts.name;
console.log(this.username);
});
angular service
getUserName(id: string) {
return this.http.get<{ posts: any }>(
`http://localhost:3000/api/user/${id}?username=` + id
);
}