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

Created on 19 Mar 2015  路  4Comments  路  Source: angular/material

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?

Most helpful comment

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

All 4 comments

@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 : thanks!

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

chriseyhorn picture chriseyhorn  路  3Comments

kasajian picture kasajian  路  3Comments

diogodomanski picture diogodomanski  路  3Comments

LeoLozes picture LeoLozes  路  3Comments