getVotes(groupId: number): Observable<Vote[]> {
let groupId = getGroupById();
return this.authService
.get('/votes/' + groupId.toString());
}
在上面的例子中,我希望根据用户的groupId获得给定组的投票。为了获取用户的groupId,我尝试了以下方法:
getGroupbyId(){
this.http.get(`${environment.apiUrl}/groups`);
}
ngOnInit() {
this.myProfile = this.route.snapshot.data.profile;
this.getGroups();
this.getVotes();
this.getVoteInsights();
this.getProfileInsights();
this.getGroupInvites();
}
private getGroups(): void{
this.groupService.getGroups()
.subscribe(
groups => this.groups = groups
);
}
private getVotes(): void {
this.voteService.getVotes(this.groupId)
.subscribe(
votes => this.votes = votes
);
}
API调用getGroups的输出如下:
{
"id": 1,
"name": "Sid's Test Group",
"imageUrl": "",
"about": "Sid's Test Group",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
},
{
"id": 2,
"name": "Sid's Test Group",
"imageUrl": "",
"about": "Testing Create Group",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
},
{
"id": 3,
"name": "Sid's Test Group",
"imageUrl": "",
"about": "Testing Create Group",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
},
{
"id": 4,
"name": "Sid's Test Group",
"imageUrl": "",
"about": "Testing Create Group",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
},
{
"id": 5,
"name": "Sid's Test Group",
"imageUrl": "",
"about": "A Test Group created by Sid",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
},
{
"id": 6,
"name": "Another Test Group",
"imageUrl": "",
"about": "Testing 123",
"membershipApprovalType": 0,
"groupInviteType": 0,
"groupType": 0
}
我想要一些关于如何最好地存储getGroupbyId调用中的所有groupId的指导,从UI传递所选的groupId并在getGroupbyId调用中使用它。