Type object is not assignable to type any[]

前端 未结 1 427
清歌不尽
清歌不尽 2020-12-22 04:49

I am using PrimeNG datatable. I using httpClient in Angular to fetch some mock data from JSON Placeholder. It appears in my console as an array of objects, however the Visua

相关标签:
1条回答
  • 2020-12-22 05:21

    If you do not specify the type that is returned from your http request, the http client assumes its an Object. This is causing the type mismatch error that you are seeing. You are trying to assign type Object to type any[]. You can specify the return type by doing

    this.http.get<any[]>(this.ROOT_URL).subscribe(...);
    
    0 讨论(0)
提交回复
热议问题