我想创建FormControl用,然后可以在我的自定义窗体控件可以用来改变行为的一些附加属性的子类。
我试图从FormControl(说StandardFormControl)如下,并用于创建表单组,但是当我访问指令内formcontrol /其他地方,我没有得到的子类的表单控件的属性继承。
class StandardFormControl extends FormControl{
customProperty: string
}
形式组已创建如下面
new FormGroup({
firstName: new StandardFormControl('',[])
});
任何人有任何想法?
据我所知,你必须强制转换的形式控制:
// first create the form group and store it in a variable:
const formGroup = new FormGroup({
firstName: new StandardFormControl('',[])
});
// then you can access its controls:
(formGroup.get('firstName') as StandardFormControl).customProperty = 'customValue';
你必须调用super()构造函数中继承父类。
class StandardFormControl extends FormControl{
customProperty: string
constructor() {
super();
}
}