新属性“验证”我喜欢在我的angula2/ionic2应用以下形式:Angular2错误:无法在数
<form [ngFormModel]="subscribeForm" (ngSubmit)="onSubmit(subscribeForm.value)">
...
<ion-item>
<ion-label floating>Survey object size</ion-label>
<ion-input type="text" [ngFormControl]="size"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Survey object path</ion-label>
<ion-input type="text" [ngFormControl]="path" [(ngModel)]="path"></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Survey object type</ion-label>
<ion-select [ngFormControl]="type">
<ion-option *ngFor="let type of survey_types">{{type}}</ion-option>
</ion-select>
</ion-item>
<br/><br/>
<button type="submit" class="custom-button" block>Submit</button>
</form>
而且我处理它在我的组件,如下所示:
export class Subscription{
subscribeForm: ControlGroup;
object_name: any;
email: any;
subscriber_name: any;
size: any;
path: any;
cycle: AbstractControl;
cycle_options=['ONCE', 'WEEKLY', 'MONTHELY']
type: AbstractControl;
survey_types=['FARM', 'SOLARPANEL', 'PLAIN']
constructor(params: NavParams, private fb: FormBuilder) {
this.size = params.get('size');
this.path = params.get('path');
this.subscribeForm = fb.group({
'object_name': '',
'email':'',
'subscriber_name':'',
'size':'',
'path':'',
'cycle':['', Validators.nullValidator],
'object_type':['', Validators.nullValidator]
});
this.object_name = this.subscribeForm.controls['object_name'];
this.email = this.subscribeForm.controls['email'];
this.subscriber_name = this.subscribeForm.controls['subscriber_name'];
this.cycle = this.subscribeForm.controls['cycle'];
this.type = this.subscribeForm.controls['type'];
}
onSubmit(value){
console.log(value)
}
}
有了这个,我得到一个错误:TypeError: Cannot create property 'validator' on number '14808.18276685957'
我的表单中有两个选择字段,我不确定我是否正确使用它们,并在我的组件中正确绑定它们的值。
我在做什么错?
更新:我得到两个NavParams并将它们的值分配给一个窗体控件,以便预先填充值。它看起来像它抛出一些验证错误Cannot create property 'validator' on number '14772.975244232435'
这是路径
如果您删除了其他所有内容,您是否仍然收到错误消息?如果不是,请删除与错误无关的代码。 –
更新了我的HTML代码片段以及问题。 – Nitish