angularjsangularjs-ng-model

Radio button value not updating after angularjs update to 1.8


After AngularJS update to 1.8, once I click and call DayTypechange(2) method, the radio button value does not update. Here is my 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>

Solution

  • You should consider using ng-change for input clicks like checkboxes, radios and selects.

    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>