【问题标题】:error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ ; }' has no compatible call signatures错误 TS2349:无法调用其类型缺少调用签名的表达式。类型 '{ ; }' 没有兼容的调用签名
【发布时间】:2020-05-17 14:29:11
【问题描述】:

我正在使用 Angular JS 打字稿(数据来自后端 springmicroservices。 我正在开发名为 downloadExcel( ) 的新方法

在我的 component.ts 中

  Data: {
    //rownum: '',
   // requestID: '',
    student_id: string,
    date: Date,
    // 'month_id': ''
  };

在方法中 =>

   ExcelDownload() {

    const subHeader1 = worksheet.addRow(this.headerData);
    subHeader1.getCell(4).value = this.Data(student_id. date); // I do want to retrieve student id and date on my cell (just 2 data)

我得到的错误

ERROR in src/app/Summary/Summary.component.ts(902,35): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type '{ student_id: string; date: Date; }' has no compatible call signatures.

任何建议!谢谢

【问题讨论】:

  • 不是因为你的类型是'student_id',而你在上面写了'studnet_id'吗?这个调用对我来说也很奇怪,因为对象有';'分隔 2 个属性(至少在您编写的错误行处)。对我来说,它应该是 ',' 而不是 ';'。只是猜测

标签: javascript java html angularjs typescript


【解决方案1】:

替换

subHeader1.getCell(4).value = this.Data(student_id. date); 

subHeader1.getCell(4).value = `${this.Data.student_id} ${this.Data.date}`;

数据不是函数

并且在您的数据对象中 studnet_id 应该是 student_id

【讨论】:

  • 如果我的代码如下: subHeader1.getCell(4).value = this.Data;输出 {"rownum":null,"requestId":null,"student_id":"0001","date":"2019-10-09T07:00:00.000+0000","month_id":null} 我确实想要检索学生 ID 0001 日期:2020 年 10 月 9 日(日期格式正确)
猜你喜欢
  • 2017-10-11
  • 2023-03-20
  • 1970-01-01
  • 2020-02-07
  • 1970-01-01
  • 1970-01-01
  • 2019-01-26
  • 2020-01-29
  • 1970-01-01
相关资源
最近更新 更多