2016-04-25 75 views
0

这是我的代码。当我提交switchColors时,服务器返回undefined。这是怎么回事?如何在Angular中做单选按钮

另外我应该如何在控制器中启动$ 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

可能帮助你http://stackoverflow.com/questions/36244427/angular-js-inputradio-doesnt-work/36244545#36244545 –

回答

1

尝试使用NG-值,而不是价值

<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> 
+0

我想我在我的控制器中启动switchColors不正确,现在我正在做'$ scope.switchColors ='';' –

+0

我应该做一些不同的事情吗?因为现在我无法在文档中选择按钮 –

+0

:它们使用值而不是ng值。 https://docs.angularjs.org/api/ng/input/input%5Bradio%5D –

相关问题