Hi this is my angular project and I want to get userName of user for every posted comment. The entities are from my spring boot project. Is there a way to get a username for every comment?
This is comment log.
This is my comments Service class
getAllCommentsForPost(postId: string): Observable<Comment[]>{
return this.http.get<Comment[]>(this.PATH_OF_API + "/api/comment/get"+postId)
}
This is my component
comments!: Comment[];
constructor(private router: Router,private postService: PostService, private commentService: CommentService) { }
this.commentService.getAllCommentsForPost(this.router.url).subscribe((data: Comment[]) =>{
this.comments = data;
})
Html
<div class="mb-1" style="width: 60%" *ngFor="let comment of comments">
{{comment.comment}}
<p *ngIf="comment.voteCount > 0" class="likes" style="color: green"> Likes: {{comment.voteCount}} </p>
<p *ngIf="comment.voteCount == 0" class="like" style="color: black"> Likes: {{comment.voteCount}} </p>
<p *ngIf="comment.voteCount < 0" class="likes" style="color: red"> Likes: {{comment.voteCount}} </p>
<a [routerLink]="['/like', comment.commentId]"> <p>like</p> </a>
</div>
I am getting error when i add
{{comment.user.userName}}
{{comment.user['userName']}}
this is my comment and user class
export class Comment {
commentId!: number;
comment!: string;
voteCount!: number;
dateCreated!: string;
user!: string;
postId!: number;
}
export class User {
userName!: string;
userPic!: string;
gender!: string;
}
