我的代码:
<input #rtc="ngForm"
type="number"
min="1"
max="43200"
style="text-align: center"
[(ngModel)]="device.rtc"
ngControl="rtc"
required>
在ngControl
不跟踪数字式输入有效的状态。我如何为输入实现验证器?
这是我的测试代码:
镖:
class MyComponent
{
Control ctrlRtc = new Control('test', rtcValidator);
static Map<String, bool> rtcValidator(Control control)
{
print(111);
}
}
HTML模板:
<input
#deviceRtc="ngForm"
type="number"
min="1"
max="43200"
style="text-align: center"
[(ngModel)]="device.rtc"
ngControl="ctrlRtc" <!-- also tried 'rtc'-->
>
控制台中永远不会显示“ 111” ...
就像是:
this.myForm = fb.group({
'rtc': ['', MyValidator.validate]
});
class MyValidator {
static Map<String, bool> validate(Control control) {
if(control.value !...) {
return {'someErrorKey': true};
}
return null;
}
}
(未测试)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句