Ste*_*eve 3 angular angular4-forms
我正在尝试创建带有一些附加属性的 FormControl 子类,然后可以在自定义表单控件中使用这些属性来更改行为。
我尝试继承 FormControl(例如 StandardFormControl),如下所示,并用于创建表单组,但是当我在指令/其他任何地方访问表单控件时,我没有获得子类表单控件的属性。
class StandardFormControl extends FormControl{
customProperty: string
}
Run Code Online (Sandbox Code Playgroud)
表单组创建如下
new FormGroup({
firstName: new StandardFormControl('',[])
});
Run Code Online (Sandbox Code Playgroud)
有人有什么想法吗?
小智 5
据我所知,你必须对表单控件进行类型转换:
// 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';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2907 次 |
| 最近记录: |