从角度2打字稿中的复选框获取价值 [英] Getting value from checked box in angular 2 typescript

查看:63
本文介绍了从角度2打字稿中的复选框获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 2 Typescript.我遇到一个需要提交包含复选框的表单的问题.我需要复选框属性中的值.这些复选框是动态的,因此可以有任意数量的复选框.

I am using Angular 2 Typescript. I am facing a problem wherein I need to submit a form which contains check boxes. I need values that are in the attributes of checkboxes. The checkboxes are dynamic, so any number of checkboxes will be there.

 <div class="checkbox" *ngFor="#label of labelList">
      <div class="col-sm-4">
           <label><input type="checkbox" value="{{label.Id}}">{{ label.Name }}</label>
      </div>   
 </div>

推荐答案

我认为这应该有效(未经测试)

I think this should work (not tested)

<div class="checkbox" *ngFor="let label of labelList">
  <div class="col-sm-4">
    <label>
      <input type="checkbox" value="{{label.Id}}" (change)="checkboxes[$event.target.getAttribute('value')]=$event.target.checked">
        {{ label.Name }}</label>
  </div>   
</div>

并将更改的复选框的值存储在组件的checkboxes中.

and store the values of changed checkboxes in checkboxes in your component.

这篇关于从角度2打字稿中的复选框获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆