What is the reason for "ERROR TypeError: this.onChange is not a function"?

What is the reason for "ERROR TypeError: this.onChange is not a function"?

我的密码是here.

请问浏览器return出现以下错误信息:

ERROR TypeError: this.onChange is not a function
at RichTextEditorComponent.forwardEvent (rich-text-editor.component.ts:39)
at Object.eval [as handleEvent] (RichTextEditorComponent.html:6)

我试图打印 "this" 对象到控制台,它 return 只是 "RichTextEditorComponent" 对象。

虽然 onChange 的类型是一个函数,但我没有看到任何实际设置值的东西,它是未定义的(因此不是函数)。

rich-text-editor.component.ts中:

onChange: (value:any) => {};

// and

registerOnChange(fn: any) {
  this.onChange = fn;
}

没有调用 registerOnChange 来设置 onChange 的值。

您的 RichTextEditorComponent 内部存在问题,您将 onChangeonTouched 声明为 function 类型,但并未真正为它们分配实际功能。

onChange: (value:any) => {};
onTouched: () => {};

应该改写如下(使用=

onChange = (value:any) => {};
onTouched = () => {};