Philippe Corrèges Philippe Corrèges - 4 years ago 118
TypeScript Question

How to access particular Observable items?

I have a function:

getCategories(): Observable<any>
return this.category.find({where: {clientId: this.userApi.getCurrentId()}})

where this.category.find return type is

I call getCategories() with:

const source = this.categoryService.getCategories();
const example =>;
const subscribe = example.subscribe(val => console.log(val));

and is undefined

If I run:

const source = this.categoryService.getCategories();
const subscribe = source.subscribe(val => console.log(val));

directly, the output is :
enter image description here

I think I have a type problem somewhere but cannot figure it out.

Any idea ?

Thanks and Regards,

Answer Source

As an array of categories is returned by the getCategories() and not just a single category as is evidenced by your subscribe's console log.

You could try something like:

const example = => => {return}));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download