I have a service which return observables of an object array
allFruits: Fruit[] = [
{
id: "1",
name: "fruit 1"
},
{
id: "2",
name: "fruit 2"
},
{
id: "3",
name: "fruit 3"
},
{
id: "4",
name: "fruit 4"
}
];
function getFruits {
return of(allFruits);
}
Component
allFruits: Observable<Fruit[]>;
constructor(
private fruitService: FruitService
) {
this.fruitService
.getFruits()
.pipe(first())
.subscribe(() => {
results => this.allFruits == results;
});
this.allFruits is always undefined and it does not have any values in there. If I do console.log(results) I do get the values