【发布时间】:2016-05-24 23:15:28
【问题描述】:
我有以下代码sn-ps
.html
<input type = "number"
min = "0"
max = "120"
#yearsCtrl = "ngForm"
[ngFormControl] = "ageForm.controls['yearsCtrl']"
[(ngModel)] = "age.years"
id = "years">
.dart
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 的反向转换也可能是一个问题。
感谢任何帮助。
谢谢
【问题讨论】:
标签: dart angular angular2-forms