Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ion-radio does not change value when clicking #1464

Closed
sesteva opened this issue May 21, 2014 · 7 comments
Closed

ion-radio does not change value when clicking #1464

sesteva opened this issue May 21, 2014 · 7 comments
Assignees

Comments

@sesteva
Copy link

sesteva commented May 21, 2014

 <ion-radio ng-model="pizza.size" ng-value="small">Small</ion-radio>

When I click it does not update the model

@perrygovier
Copy link
Contributor

Can you set up an example?

It's worth noting that directives like ion-radio have their own controller/scope, so to access vars in your state's/page's scope, you'd have to reference $parent like:

 <ion-radio ng-model="$parent.pizza.size" ng-value="small">Small</ion-radio>

@sesteva
Copy link
Author

sesteva commented May 22, 2014

I think Im confused. The example shows no need to reference the parent and based on the code the directive captures the model into the scope.
I ll try to recreate in a plunker.

IonicModule
.directive('ionRadio', function() {
  return {
    restrict: 'E',
    replace: true,
    require: '?ngModel',
    scope: {
      ngModel: '=?',
      ngValue: '=?',
      ngChange: '&',
      icon: '@',
      name: '@'
    },
    transclude: true,
    template: '<label class="item item-radio">' +
                '<input type="radio" name="radio-group"' +
                ' ng-model="ngModel" ng-value="ngValue" ng-change="ngChange()">' +
                '<div class="item-content disable-pointer-events" ng-transclude></div>' +
                '<i class="radio-icon disable-pointer-events icon ion-checkmark"></i>' +
              '</label>',

    compile: function(element, attr) {
      if(attr.name) element.children().eq(0).attr('name', attr.name);
      if(attr.icon) element.children().eq(2).removeClass('ion-checkmark').addClass(attr.icon);
    }
  };
});

@ericwooley
Copy link

I had the same issue and I have been playing around with the source some.

IonicModule
.directive('ionRadio', function() {
  return {
    restrict: 'E',
    replace: true,
    require: '?ngModel',
    scope: {
      ngModel: '=?',
      ngValue: '=?',
      ngChange: '&',
      icon: '@',
      name: '@'
    },
    transclude: true,
    template: '<label class="item item-radio">' +
                '<input type="radio" name="radio-group"' +
                ' ng-model="ngModel" ng-value="ngValue" ng-change="ngChange()">' +
                '<div class="item-content disable-pointer-events" ng-transclude></div>{{ngModel}} - {{ngValue}}' + // MODIFIED HERE
                '<i class="radio-icon disable-pointer-events icon ion-checkmark"></i>' +
              '</label>',

    compile: function(element, attr) {
      if(attr.name) element.children().eq(0).attr('name', attr.name);
      if(attr.icon) element.children().eq(2).removeClass('ion-checkmark').addClass(attr.icon);
    }
  };
});

I added {{ngModel}} - {{ngValue}} to the template as text, and the model does appear before you click on the ion-radio. However, ngValue does not.

It seems to me that the ngValue is not being retrieved and once you click on one of the radio icons you set the model to "". In my case, the model was already empty which made it appear as if there was nothing happening.

@ericwooley
Copy link

I figured it out. The value was being accepted as a value not variable not as a value.

IonicModule
.directive('ionRadio', function() {
  return {
    restrict: 'E',
    replace: true,
    require: '?ngModel',
    scope: {
      ngModel: '=?',
      ngValue: '=?',// WRONG
      ngValue: '@',// CORRECT
      ngChange: '&',
      icon: '@',
      name: '@'
    },
    transclude: true,
    template: '<label class="item item-radio">' +
                '<input type="radio" name="radio-group"' +
                ' ng-model="ngModel" ng-value="ngValue" ng-change="ngChange()">' +
                '<div class="item-content disable-pointer-events" ng-transclude></div>' +
                '<i class="radio-icon disable-pointer-events icon ion-checkmark"></i>' +
              '</label>',

    compile: function(element, attr) {
      if(attr.name) element.children().eq(0).attr('name', attr.name);
      if(attr.icon) element.children().eq(2).removeClass('ion-checkmark').addClass(attr.icon);
    }
  };
});

So the source needs to be changed to make it work correctly.

@perrygovier
Copy link
Contributor

When #1500 is approved and closed, this can be closed as well.

@rknell
Copy link

rknell commented Nov 11, 2014

I had the same problem but the $parent worked for me.

+1 For not mentioned in the documentation - which even goes as far as to say it works exactly the same as an angular control and sends you there with a link.

Is there some way I can contribute to the documentation and create a pull request?

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 6, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants