【问题标题】:send checkbox value through formgroup in angular通过表单组以角度发送复选框值
【发布时间】:2020-12-29 21:54:53
【问题描述】:

我是 Angular 新手,我想在表单组中发送复选框值。我在该字段中有 2 个复选框可以帮助我。

masterList: {
        type: String,
        read: true,
        write: true
    },
    eventlist:{
        type: String,
        read: true,
    },
    feedBackSubmission: {
        type: String,
        read: true,
        write: true
}

这是我的 json,我想发送他们的名字并从我的页面读取写入值

这是我的html代码

 <tr>
        <th style="border: 1px solid black;">Feedback Submission</th>
       <td style="border: 1px solid black;"><input type="checkbox"></td>
        <td style="border: 1px solid black;"><input type="checkbox" ></td>
        </tr>

这是我的 ts

  roleForm = this.fb.group({
    name: [null, [Validators.required]],
    description: [null, [Validators.required]],
    feedBackSubmission:[null,[Validators.required]],
    // eventStatusList:[null,[Validators.required]],
    // exercisestatus:[null,[Validators.required]],
    // uservariableList:[null,[Validators.required]],

  });

我想在表单中发送这些复选框的值(真/假)

【问题讨论】:

    标签: angular


    【解决方案1】:

    这是为了一张桌子?如果是,您将需要一种不同的方法。

    我根据 whitout 表制作。

    HTML

    <ng-container [formGroup]="roleForm">
        <tr>
            <th style="border: 1px solid black;">Feedback Submission</th>
            <td style="border: 1px solid black;">
                <input formControlName="feedBackSubmission" type="checkbox">
            </td>
        </tr>
    </ng-container>
    

    TS

    this.roleForm = this.fb.group({
      name: [null, [Validators.required]],
      description: [null, [Validators.required]],
      feedBackSubmission: [null, [Validators.required]]
    });
    

    表单值

    {
        "name": null,
        "description": null,
        "feedBackSubmission": true
    }
    

    Stackblitz sample

    【讨论】:

    • 先生,是的,先生,这是用于表格中的表格,我有 2 个选项,即读取和写入,我想在您的示例中传递两个值,您只传递一个值
    • 在这种情况下,您将需要使用 FormArray。 this is a sample with material table
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 1970-01-01
    • 2021-05-25
    • 1970-01-01
    • 2018-04-27
    • 2016-07-16
    相关资源
    最近更新 更多