I provide a service that returns observables of an array of objects
allItems: Item[] = [
{
id: "1",
name: "item 1"
},
{
id: "2",
name: "item 2"
},
{
id: "3",
name: "item 3"
},
{
id: "4",
name: "item 4"
}
];
function getItems {
return of(allItems);
}
Component
allItems: Observable<Item[]>;
constructor(
private itemService: ItemService
) {
this.itemService
.getItems()
.pipe(first())
.subscribe(() => {
results => this.allItems == results;
});
this.allItems is always undefined and it does not have any values in there. If I do console.log(results) I do get the values