如何在Angular中执行单选按钮

时间:2016-04-25 06:59:50

标签: javascript html angularjs user-interface radio-button

这是我的代码。当我提交switchColors时,服务器返回undefined。这怎么回事?

另外我应该如何在我的控制器中启动$ scope.swichColors?目前我有$ scope.switchColors ='';

<label class="radio-inline">
    <input type="radio" ng-model="$parent.switchColors" value = "yes" >Yes</input>
</label>

<label class="radio-inline">
    <input type= "radio" ng-model = "$parent.switchColors" value = "no" >No</input>
</label>

1 个答案:

答案 0 :(得分:1)

尝试使用ng-value而不是value

 <label class="radio-inline">
        <input type="radio" ng-model="$parent.switchColors" ng-value = "yes" >Yes</input>
    </label>

    <label class="radio-inline">
        <input type= "radio" ng-model = "$parent.switchColors" ng-value = "no" >No</input>
    </label>