【发布时间】:2017-12-09 04:17:06
【问题描述】:
我正在尝试向 Angular 的 FormGroup 类添加一个额外的方法,该方法将设置组的状态 + 从服务器设置错误状态。
我的 Angular4 应用程序的 form-helper.ts 文件中有以下代码。
import { FormGroup } from '@angular/forms';
export interface FormGroup {
setValueAndErrors(state: any, memberErrors: any);
}
FormGroup.prototype.setValueAndErrors = (state: any, memberErrors: any) => {
this.setValue(state);
// do some stuff with the memberErrors parameter
}
但编译器在FormGroup.prototype.setValueAndErrors 行抛出错误。
C:/dev/AppName/AppName-Client/src/app/shared/utils/form-helper.ts (3,21) 中的错误:“FormGroup”类型上不存在属性“setValueAndErrors”。
【问题讨论】:
-
除了你提到的错误之外,
this不会是你所期望的箭头函数。 -
我可以跨过那座桥 :) 现在我只想知道为什么它没有编译
标签: angular typescript