如何拉出所选的单选按钮值?

时间:2018-01-24 07:53:51

标签: angular angular2-forms

我的HTML中有多个单选按钮,当我点击“保存”按钮时,我想选中单选按钮进行检查。

HTML代码

<div id="" class="workdlowreasons" *ngFor="let reason of workflowReasons; let i=index;">
        <input type="radio" name="reason"  id="reason_{{i}}" value="{{reason.reason}}"
        [checked]="i === 0">
        <label for="reason_{{i}}">{{reason.reason}}</label>
        </div>

DOM HTML

<form _ngcontent-c7="" novalidate="" class="ng-untouched ng-pristine ng-valid">
            <!--bindings={
  "ng-reflect-ng-for-of": "[object Object],[object Object"
}--><div _ngcontent-c7="" class="workdlowreasons" id="">
            <input _ngcontent-c7="" name="reason" type="radio" id="reason_0" value="Not Relevany to Patient">
            <label _ngcontent-c7="" for="reason_0">Not Relevany to Patient</label>
            </div><div _ngcontent-c7="" class="workdlowreasons" id="">
            <input _ngcontent-c7="" name="reason" type="radio" id="reason_1" value="Patient Shifted">
            <label _ngcontent-c7="" for="reason_1">Patient Shifted</label>
            </div><div _ngcontent-c7="" class="workdlowreasons" id="">
            <input _ngcontent-c7="" name="reason" type="radio" id="reason_2" value="Patient Discharged">
            <label _ngcontent-c7="" for="reason_2">Patient Discharged</label>
            </div><div _ngcontent-c7="" class="workdlowreasons" id="">
            <input _ngcontent-c7="" name="reason" type="radio" id="reason_3" value="Another Nurse Attending">
            <label _ngcontent-c7="" for="reason_3">Another Nurse Attending</label>
            
            <input _ngcontent-c7="" class="btn-primary btn" id="submitdecline" name="submitdecline" type="button" value="Save">
        </form>

0 个答案:

没有答案