我有以下代码片段
.html
<input type = "number"
min = "0"
max = "120"
#yearsCtrl = "ngForm"
[ngFormControl] = "ageForm.controls['yearsCtrl']"
[(ngModel)] = "age.years"
id = "years">
。镖
class Age
{
int years = 0;
}
class AgeComponent {
....
AgeComponent( FormBuilder fb, ModelService
ageSrvc) {
ageForm = fb.group( {
'yearsCtrl': [''],
} );
_yearsCtrl = ageForm.controls['yearsCtrl'];
age = new Age()
}
...
}
我尝试运行该应用程序时出现以下错误(部分)
>EXCEPTION: type 'String' is not a subtype of type 'num' of 'value'. in [AST]
EXCEPTION: type 'String' is not a subtype of type 'num' of 'value'. in [AST]
(anonymous function)
ORIGINAL EXCEPTION: type 'String' is not a subtype of type 'num' of 'value'.
(anonymous function)
ORIGINAL STACKTRACE:
(anonymous function)
#0 NumberValueAccessor.writeValue (package:angular2/src/common/forms/directives/number_value_accessor.dart:38:23)
#1 setUpControl (package:angular2/src/common/forms/directives/shared.dart:34:21)
#2 NgFormControl.ngOnChanges (package:angular2/src/common/forms/directives/ng_form_control.dart:111:7)
...
似乎 type="num" 没有被处理。我怀疑年龄 int 也可能是一个问题,因为它是一个 int 但需要一个字符串。从 sting 返回到 int 的反向转换也可能是一个问题。
任何帮助表示赞赏。
谢谢