【问题标题】:Angular 2 forms; ngFormControl for radio and selectAngular 2 形式; ngFormControl 用于广播和选择
【发布时间】:2016-05-24 16:15:49
【问题描述】:

我正在使用 Angular 制作应用程序,目前正在处理表单部分。在自定义 ngFormModel 的帮助下,我可以通过以下验证生成每个定义的表单:

<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>

这非常棒,我的预定义表单的默认值会自动显示,并且我的表单会在我提交值时更新。我无法获取输入类型收音机并使用 ngFormControl 选择启动和运行。 Angular 2中是否有可能不支持开箱即用?这不是表单的一个非常基本的部分吗?

编辑:可能与显示表单的生成方式有关:

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

【问题讨论】:

    标签: angular angular2-forms


    【解决方案1】:

    无线电输入尚未得到很好的支持,并且存在各种已知问题。 另见https://github.com/angular/angular/issues/8107https://github.com/angular/angular/search?q=radio&state=open&type=Issues&utf8=%E2%9C%93

    【讨论】:

    • 选择类型怎么样?我也找不到很多关于此的内容,但可以用来构建解决方法。
    • 选择应该可以工作。您使用的是什么 Angular2 版本?我没有看到您的问题中使用了选择。你试过什么?什么不起作用。
    • 我试图在 plunker 中做一个例子,但发现 select 类型确实按预期工作,问题仅在于无线电类型。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2018-01-28
    • 1970-01-01
    • 2017-02-02
    相关资源
    最近更新 更多