Angular: error TS2322: Type 'ItemsResponse' is not assignable to type 'string[]'

前端 未结 2 1231
礼貌的吻别
礼貌的吻别 2020-12-21 06:26

I am getting this error with my component not sure what to do?

here is the component:

import { Component, OnInit } from \'@angular/core\';
import { H         


        
2条回答
  •  醉梦人生
    2020-12-21 07:00

    here: this.http.get you are declaring that http.get's response data's type would be of ItemsResponse. and before that, inside your class you are declaring that results is an array of strings: results: string[];. but inside http's response, you are assigning the response to this.results. try this.results = data.results. but make sure that the type of the response is truly of type ItemsResponse. maybe use console.log

提交回复
热议问题