I am using angular 4 and I am trying to get data from two endpoints, but I have a problem understanding rxjs.
With this code I can only get a list of students and users.
getStudent() {
return this.http.get(this.url + this.student_url, this.getHeaders()).map(res => res.json());
}
getUsers() {
return this.http.get(this.url + this.users_url, this.getHeaders()).map(res => res.json());
}
Say this data: Student
[{"ID" : 1 , "SchoolCode": "A150", "UserID": 1 },
{"ID" : 5 , "SchoolCode": "A140" , "UserID": 3},
{"ID" : 9 , "SchoolCode": "C140" , "UserID": 4}]
User
[{"ID" : 1 ,"Name": "Rick" , "FamilyName" , "Grimes" },
{"ID" : 4 ,"Name": "Carle" , "FamilyName" , "Grimes" }]
I want to get all the students first, and then compare the UserID, if it is the same as the user, then I will combine both objects into one until I get such an array:
{"ID" : 1 , "SchoolCode": "A150","Name": "Rick" , "FamilyName" , "Grimes" }
I think I should use flatmap, but I really tried to write the code, but it does not work for me, and I did not find an example with such logic.
Could you help me.