Я получаю 3 раза один и тот же массив, когда вставляю свой массив в тему rxjs.
Родительский компонент:
const geoExistsArr: { lat: number, lng: number }[] = [];
for (let i = 0; i < x.length; i++) {
for (let j = 0; j < requiredKeys.length; j++) {
// Some logic
}
if (has(x[i].data, 'lat') && has(x[i].data, 'lng')) {
// Pushing to array
const { lat, lng } = x[i].data;
geoExistsArr.push({ lat, lng })
}
}
console.log(geoExistsArr)
// Adding the array to subj.
this.locationSrv.setLocations(geoExistsArr)
Служба:
setLocations(loc: ILocation) {
this.geoArray = [...this.geoArray, loc]
this.geoSubj$.next(this.geoArray)
}
Дочерний компонент (отображение значений от субъекта):
this.geoLocation$ = this.locationSrv.geoCoordinates$.pipe(
switchMap((geo, idx) => {
console.log(geo, idx) // <- problem here. this guy prints 3 times.
geo.forEach(g => {
console.log(g)
requests.push(this.locationSrv.getAddressByLatLng$(g))
});
return concat(...requests).pipe(
toArray()
)
}),
Что должно произойти: я сохраняю отдельный массив для субъекта.
Я ослеп на эту ошибку, поэтому любая помощьбыл бы оценен!