angularjs更新为1.8后单选按钮值未更新

xqnpmsa8  于 2021-09-29  发布在  Java
关注(0)|答案(1)|浏览(309)

angularjs更新到1.8后,一旦我点击并调用 DayTypechange(2) 方法时,单选按钮值不会更新。这是我的html:

<div class="btn-group btn-group-sm col-xs-11 col-md-10 select topmargine">
    <div class="col-xs-6 col-sm-6 select">
        <input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(1)' ng-class="{selected: fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="wholeDay" ng-value="'1'" />
        <label class="col-xs-10 formtextNormal" for="wholeDay">Whole day(s)</label>
    </div>
    <div class="col-xs-6 select">
        <input type="radio" name="response" ng-model="fullDay" ng-click='DayTypechange(2)' ng-class="{selected: !fullDay}" class="col-xs-2 col-sm-2 col-md-2 col-lg-2" id="partDay" ng-value="'0'" />
        <label class="col-xs-10 formtextNormal" for="partDay">Part day</label>
    </div>
</div>
rur96b6h

rur96b6h1#

您应该考虑使用NG更改来进行输入点击,如复选框、无线电和选择。

angular.module('changeExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
    $scope.confirmed = "No"
    $scope.change = function() {
      console.log('radio clicked of value ', $scope.confirmed)
    };
  }]);
<html ng-app='changeExample'>
<head><script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script></head>
<body ng-controller="ExampleController">
  <label><input type="radio" ng-model="confirmed" value="Yes" ng-change="change()" name='changer' /> Yes</label>
  <label><input type="radio" ng-model="confirmed"  name='changer' value="No"  ng-change="change()" />NO</label>
  <hr><div>Current radio = {{confirmed}}</div>
</body></html>

相关问题