material icon indicating copy to clipboard operation
material copied to clipboard

Issue with ngChange function of md-radio-button component/directive

Open balteo opened this issue 11 years ago • 4 comments

It seems there's an issue with the ngChange function of md-radio-button.

Using the following code, the changeNeed function is never called when the user select one of the radios:

<md-radio-group>
        <md-radio-button ng-model="advertisement.need" ng-change="changeNeed(need)" ng-repeat="need in needs" name="need" ng-required="true" ng-value="need">
                {{'DOMAIN_ENUM_NEED_DESCRIPTION_' + need | translate}}
        </md-radio-button>
    </md-radio-group>

I have tried moving the ng-model="advertisement.need" ng-change="changeNeed(need)" attributes into the md-radio-group but then of course the ng-repeat item (here need) is no longer available...

Is there a way to circumvent this issue?

balteo avatar Mar 19 '15 12:03 balteo

@balteo

First of all, ng-model and ng-change are only allowed on md-radio-group element. You have two options to get desired behavior:

  1. Put ng-click="changeNeed(need)" on md-radio-button
  2. Put ng-change="onChangeNeed()" on md-radio-group and implement it like this:
$scope.onChangeNeed = function() {
  var updatedNeed = $scope.advertisement.need;
  // Do something with the new value of advertisement.need
};

sazonenka avatar Mar 24 '15 07:03 sazonenka

@sazonenka : thanks!

balteo avatar Mar 24 '15 07:03 balteo

Documentation is incorrect. ngChange is listed as belonging to md-radio-button: https://material.angularjs.org/latest/api/directive/mdRadioButton

STOpandthink avatar Jan 15 '16 00:01 STOpandthink

Documentation is still incorrect. Is not possible to use ngChange on a md-radio-button but only ngClick https://material.angularjs.org/latest/api/directive/mdRadioButton

ghost avatar Jun 14 '16 09:06 ghost