I have been struggling to compare two observable methods and retrieve the desired output. Although I attempted an example, the expected outcome was not achieved. Hopefully, the following example (what I tried) will clarify my question.
GetCountries() : Observable<any>
{
return this.http.GetCountries().subscribe(data => {
return data;
})
}
GetSelectedCities() : Observable<any>
{
return this.http.GetCities().map(data => {
return data
});
}
let cities = [{name:'new york', id:1},
{name:'paris', id:2},
{name:'london', id:3}]
let countries = [{name:'usa', id:1, city:'new york'},
{name:'germany', id:2,city:'berlin'},
{name:'france', id:3,city:'marseille'},
{name:'netherland', id:3,city:'amersterdam'}]
GetNotSelectedCities()
{
this.GetCountries.do(data => {
this.GetSelectedCities.do(response => {
data.filter(x=> return response.filter(d=> d.city !== x.name ) )
})
})
}
However, despite my efforts, I am receiving a list of cities instead of the intended result:
[{name:'germany', id:2,city:'berlin'},
{name:'france', id:3,city:'paris'},
{name:'netherland', id:3,city:'amsterdam'}]