简体   繁体   English

AngularJs输入单选值

[英]AngularJs Input radio value

I've got a form where a user has to say if he is male or female . 我有一个表格,用户必须说出他是male还是female In my database it's a 1 or 0 . 在我的数据库中,它是10 How could I make this with AngularJs input radio . 我怎么能用AngularJs input radio做到这一点。

Right now I've got this: 现在我有了这个:

<div class="form-group">
    <label class="col-md-2 control-label">Radios</label>

    <div class="col-md-10">
        <div class="radio radio-primary">
            <label>
                <input type="radio" name="male" id="male" ng-model="employeeCtrl.employee.Gender" ng-value="0"><span class="circle"></span><span class="check"></span>
                Male
            </label>
        </div>
        <div class="radio radio-primary">
            <label>
                <input type="radio" name="optionsRadios" id="optionsRadios4" ng-model="employeeCtrl.employee.Gender" ng-value="1"><span class="circle"></span><span class="check"></span>
                Female
            </label>
        </div>
    </div>
</div>

But this is not working. 但这是行不通的。 The right radio button is not selected also the value won't change. 没有选择右单选按钮,该值也不会更改。

Run the code and see is this what you expect. 运行代码,看看这是您期望的。 Use same name for radio button, and you can use different id for each controller. 为单选按钮使用相同的名称,并且可以为每个控制器使用不同的ID。

 <!DOCTYPE html> <html> <head> <script data-require="angular.js@1.5.0" data-semver="1.5.0" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-app=""> <div class="form-group"> <label class="col-md-2 control-label">Radios</label> <div class="col-md-10"> <div class="radio radio-primary"> <label> <input type="radio" id='gender_male' name="gender" ng-model="employeeCtrl.employee.Gender" ng-value="0"><span class="circle"></span><span class="check"></span> Male </label> </div> <div class="radio radio-primary"> <label> <input type="radio" id='gender_female' name="gender" ng-model="employeeCtrl.employee.Gender" ng-value="1"><span class="circle"></span><span class="check"></span> Female </label> </div> </div> Gender: {{employeeCtrl.employee.Gender}} </div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM