【问题标题】:Type 'HttpEvent<Student[]>' is not assignable to type 'Student[]'. Type 'HttpSentEvent' is not assignable to type 'Student[]'类型“HttpEvent<Student[]>”不可分配给类型“Student[]”。类型 'HttpSentEvent' 不可分配给类型 'Student[]'
【发布时间】:2019-06-02 04:01:51
【问题描述】:

错误 TS2322 (TS) 类型“HttpEvent”不可分配给 输入“学生 []”。类型“HttpSentEvent”不可分配给类型 '学生[]'。 “HttpSentEvent”类型中缺少属性“长度”。

我的代码行出现上述错误:

声明

 public Students: Array<Student> = [];
 model: any = {};


constructor(private httpService: HttpClient) {
}

async  LoadStudentData() {
    var t = await this.httpService.get<Array<Student>>(URL, this.model).toPromise();

    this.Students = t;

}

有什么方法可以进行选角吗?

【问题讨论】:

  • 什么是组织和学生类型和关系?
  • 更新问题

标签: angular typescript async-await


【解决方案1】:

感谢您的建议。

如下修改我的等待调用对我有用

var t = await this.httpService.get<Student[]>(URL, { params: this.model, observe: 'body' })
        .toPromise();

this.Students = t;

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 2020-08-24
    • 2021-05-21
    • 2019-01-12
    • 2018-04-19
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 2020-04-02
    相关资源
    最近更新 更多