확장 진단

이벤트 바인딩에서는 함수를 호출해야 합니다

이 진단은 이벤트 바인딩에서 호출하지 않은 함수를 감지합니다.

import {Component, signal, Signal} from '@angular/core';

@Component({
  template: `<button (click)="onClick">Click me</button>`,
})
class MyComponent {
  onClick() {
    console.log('clicked');
  }
}

무엇이 문제인가요?

이벤트 바인딩의 함수는 이벤트가 발생했을 때 호출되어야 합니다. 함수를 호출하지 않으면 이벤트가 발생해도 함수가 실행되지 않습니다.

어떻게 해결하나요?

이벤트 바인딩에서 함수를 사용할 때는 이벤트가 발생하면 함수가 실행되도록 함수를 호출하세요.

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

@Component({
  template: `<button (click)="onClick()">Click me</button>`,
})
class MyComponent {
  onClick() {
    console.log('clicked');
  }
}

필수 설정

확장 진단이 발생하려면 strictTemplates를 활성화해야 합니다. uninvokedFunctionInEventBinding에는 strictTemplates 외의 추가 요구 사항이 없습니다.

이 상황을 피할 수 없다면 어떻게 하나요?

프로젝트의 tsconfig.json 파일을 수정하여 이 진단을 비활성화할 수 있습니다.

{
  "angularCompilerOptions": {
    "extendedDiagnostics": {
      "checks": {
        "uninvokedFunctionInEventBinding": "suppress"
      }
    }
  }
}

자세한 내용은 확장 진단 설정을 참고하세요.