medzvre gena
medzvre gena

Reputation: 145

Angular 11 : error TS2339: Property 'data' does not exist on type 'Object' but everything works fine

So I used an API to get some pictures from it and add them to the slider.

Everything works the way it should but there is just this annoying error :DD don't know what is the problem. I have this error in terminal

src/app/main-components/main-page/main-page.component.ts:21:34 - error TS2339: Property 'data' does not exist on type 'Object'

generateDataInCarousel() {
    let api = 'some Api'
    this.webworker.getDataFromApi(api).subscribe(respond => {
      for (let i = 0; i < respond.data.length; i++) {
        this.images.push(respond.data[i])
      }
    })
  }

any ideas what is the problem?

Upvotes: 0

Views: 680

Answers (1)

Owen Kelvin
Owen Kelvin

Reputation: 15098

This is a typescript error because httpClient returns an Object. You can either typecast to any in the httpClient call or change your code to

generateDataInCarousel() {
    let api = 'some Api'
    this.webworker.getDataFromApi(api).subscribe((respond: any)=> {
      for (let i = 0; i < respond.data.length; i++) {
        this.images.push(respond.data[i])
      }
    })
  }

Upvotes: 1

Related Questions