Having trouble getting a list from HttpClient in Angular due to issues with transforming the data from an Observable.
Even after testing with static values, the results remain unchanged. Attempts at transforming values using map() within an Observable result in unmodified outputs. Consider the following examples:
import { from, map, Observable, of } from 'rxjs';
// Example 1:
const observableOne$: Observable<number[]> = of([1, 2, 3]);
observableOne$.pipe(
map((items: number[]) => {
console.log('This will be ignored');
return items.map((item: number): number => item + 100);
}),
map((items: number[]) => {
console.log('This will also be ignored');
items.push(4);
})
);
observableOne$.subscribe((items: number[]) => console.log('First:', items));
// Output will be:
// First: [1, 2, 3]
// Example 2:
const observableTwo$: Observable<number> = from([1, 2, 3]);
observableTwo$.pipe(map((item: number) => item + 100));
observableTwo$.subscribe((items: number) => console.log('Second:', items));
// Output will be:
// Second: 1
// Second: 2
// Second: 3
Any ideas on how to address this issue?