Home > Blockchain >  can't get value of object from observable data
can't get value of object from observable data

Time:02-01

I have this data in mongoDB (important field "period" is red border) :

enter image description here I have this function that get some data:

myFunction(): void {
this.mySubscription = this.myObservable
.pipe(
  map(data => data
    .map(item => item.period))
)
.subscribe((res) => {
  for (const entry of res) {
    console.log('entry: ', entry);
  }
});

At page display, i got this output in the console :

Blockquote

but if i want to get the same way, the startDate inside 'period' object i got this error in my .ts file:

property startDate does not exists on type {}:

enter image description here

Any help on this ? Thank you !

CodePudding user response:

it doesn't know whether it will have startDate. You can get rid of that error/warning by adding any type

so it would be (diapuse:any)

  •  Tags:  
  • Related