Angular 2 forms; ngFormControl for radio and select

家住魔仙堡 提交于 2019-12-11 07:35:47

问题


I am making an app in Angular and am currently working on a forms section. With the help of a custom ngFormModel I have can generate per defined forms with validation simply with the following:

<form [ngFormModel]="customForm" (ngSubmit)="updateUser()">
<input [ngFormControl]="customForm.controls['name']" type="text">
<input [ngFormControl]="customForm.controls['email']" type="text>
            <button *ngIf="customForm.dirty" type="submit">Save</button>
</form>

This works quite awesome, default values for my pre defined form are automatically shown and my form is updated when I submit the values. I have not been able to get input types radio and select up and running with ngFormControl. Is it possible that this isn't supported out of the box in Angular 2? Isn't this a quite fundamental part of forms?

Edit: maybe relevant to show how the form is generated:

this.customForm = this.form.group({
    'name': [this.user.first_name],
    'email': [this.user.email]});

回答1:


The radio input is not yet well supported and has various known issues. See also https://github.com/angular/angular/issues/8107 or https://github.com/angular/angular/search?q=radio&state=open&type=Issues&utf8=%E2%9C%93



来源:https://stackoverflow.com/questions/37407881/angular-2-forms-ngformcontrol-for-radio-and-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!