【问题标题】:How to do radio buttons in Angular如何在Angular中做单选按钮
【发布时间】:2016-08-18 10:47:52
【问题描述】:

这是我的代码。当我提交 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>

【问题讨论】:

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


【解决方案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>

【讨论】:

  • 我认为我在控制器中错误地启动了 switchColors,现在我只是在做 '$scope.switchColors = '';'
  • 我应该做一些不同的事情吗?因为现在我无法选择按钮
  • 也在此处的文档中:他们使用 value 而不是 ng-value。 docs.angularjs.org/api/ng/input/input%5Bradio%5D
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-12
  • 1970-01-01
  • 1970-01-01
  • 2015-10-27
  • 2021-02-15
相关资源
最近更新 更多