跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

Functions should be invoked in text interpolation. ​

This diagnostic detects uninvoked functions in text interpolation.

ts
import {Component} from '@angular/core';

@Component({
  template: `{{ getValue }}`,
})
class MyComponent {
  getValue() {
    return 'value';
  }
}

What's wrong with that? ​

Functions in text interpolation should be invoked to return a value. If the function is not invoked, it will not return any value and the interpolation will not work as expected.

What should I do instead? ​

Ensure to invoke the function when you use it in text interpolation to return the value.

ts
import {Component} from '@angular/core';

@Component({
  template: `{{ getValue() }}`,
})
class MyComponent {
  getValue() {
    return 'value';
  }
}

Configuration requirements ​

strictTemplates must be enabled for any extended diagnostic to emit. uninvokedFunctionInTextInterpolation has no additional requirements beyond strictTemplates.

What if I can't avoid this? ​

This diagnostic can be disabled by editing the project's tsconfig.json file:

json
{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "uninvokedFunctionInTextInterpolation": "suppress"
      }
    }
  }
}

See extended diagnostic configuration for more info.

基于 MIT 许可证发布。