【问题标题】:AngularJS radio button disabled by function if any is selected如果选择了任何功能,则AngularJS单选按钮被功能禁用
【发布时间】:2014-04-03 16:09:43
【问题描述】:

AngularJS 还是新手,谁能解释一下为什么我不能通过功能禁用单选按钮?

<td class="column" ng-repeat="item in row">
  <input type="radio" name="countries" value="{{item.right}}" id="{{item.name}}" ng-model="answer" ng-disabled="picked(currentIndex)" ng-change="newValue({{item.right}})">
  <label for="{{item.name}}">{{item.name}}</label>
</td>

控制器:

@IndexCtrl = ($scope) ->

  $scope.currentIndex = 0
  $scope.score = 0
  $scope.answered = []

  $scope.picked = (currentIndex) ->
    if $scope.answered.indexOf(currentIndex) is not -1
      return true 
    else
      return false

  $scope.newValue = (value) ->
    $scope.answered.push($scope.currentIndex) if $scope.answered.indexOf($scope.currentIndex) is -1
    ++$scope.score if value
    return

【问题讨论】:

  • 首先,从 newValue({{item.right}}) 中删除“{{”和“}}”
  • 尝试将 ng-change="newValue({{item.right}})" 更改为 ng-change="newValue(item.right)"
  • 并将pick(currentIndex) 更改为pick($index)
  • 完成,但仍未禁用按钮。可能与不同的 $scope 有关?
  • 我认为你应该使用 ng-click,而不是 ng-change

标签: angularjs radio-button


【解决方案1】:

答案在咖啡脚本中:

is not vs isnt (=== ! vs !==) 

:-)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-15
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多