【问题标题】:Typescript cannot invoke expression whost type lacks a call signatureTypescript 无法调用类型缺少调用签名的表达式
【发布时间】:2018-01-08 08:22:37
【问题描述】:

我知道有类似的问题,但到目前为止我还没有找到任何可以回答我的问题的东西我只是想在我的 Angular 应用程序中创建一个简单的函数

app.component.ts

formClick() {

    const formContainer = <HTMLElement>document.querySelector('.form-container');
    const spinner = <HTMLElement>document.querySelector('.loading-spinner');
    const form = <HTMLElement>document.querySelector('.email-form');

    form.style.display = 'none';
    spinner.style.display = 'block';

    setTimeout(function(){
       spinner.style.display = 'none';
       formContainer.innerHTML('<h1>Thanks! We will get back to you shortly</h1>')
    }, 1000);
} 

但我在我的formContainer.innerHTML 上收到一个错误,上面写着

[ts] Cannot invoke an expression whose type lacks a call signature. Type 'String' has no compatible call signatures. (property) Element.innerHtml: string

我不确定这是什么意思,任何帮助将不胜感激,

谢谢

【问题讨论】:

  • innerHTML 不是函数。你分配给它。
  • @unional 是的,谢谢,我是个白痴哈哈

标签: angular typescript


【解决方案1】:

我认为问题出在formContainer.innerHTML('&lt;h1&gt;Thanks! We will get back to you shortly&lt;/h1&gt;') 这一行。

应该是formContainer.innerHTML = '&lt;h1&gt;Thanks! We will get back to you shortly&lt;/h1&gt;'

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 2021-02-06
    • 1970-01-01
    • 2019-09-28
    • 2019-09-10
    • 2018-12-25
    • 1970-01-01
    • 2015-08-26
    相关资源
    最近更新 更多