0

Im trying to bind value of radio button from ionic controller. The following is the code i have used for.

 <div class="list">
            <ion-radio ng-model="SearchChoice" ng-value="All" ng-click="SearchByFilter('All')"> ALL <div id="badge-all" class="count-jkt"> <span ng-bind="AllCount.OnGoing"></span></div></ion-radio>
            <ion-radio ng-model="SearchChoice" ng-value="New" ng-click="SearchByFilter('New')"> NEW <div id="badge-new" class="count-jkt">{{AllCount.New}}</div></ion-radio>
        </div>

and my controller is,

       .controller('MainCtrl', function($scope) {

         $scope.SearchChoice = "All";
        $scope.SearchByFilter = function(item) {
          console.log( "Filter:", item);
        };
      }); 

Here the value is not binding properly. Kindly help me guys!

Jonas
  • 121,568
  • 97
  • 310
  • 388
ganesh
  • 859
  • 6
  • 13
  • 29

1 Answers1

0

Could you try it using the . notation ?

<div class="list">
    <ion-radio ng-model="model.SearchChoice" ng-value="All" ng-click="SearchByFilter('All')"> ALL <div id="badge-all" class="count-jkt"> <span ng-bind="AllCount.OnGoing"></span></div></ion-radio>
    <ion-radio ng-model="model.SearchChoice" ng-value="New" ng-click="SearchByFilter('New')"> NEW <div id="badge-new" class="count-jkt">{{AllCount.New}}</div></ion-radio>
</div>

.controller('MainCtrl', function($scope) {
    $scope.model = {
        SearchChoice: "All"
    };

    $scope.SearchByFilter = function(item) {
        console.log( "Filter:", item);
    };
}); 

For more info about the . notation see here.

Community
  • 1
  • 1
Martijn Welker
  • 5,575
  • 1
  • 16
  • 26
  • Im getting the default value. but, its not shows as selected. when i remove ng-model it shows selected. But i can get value in model.SearchChoice. I dont know what i have missed! – ganesh Feb 16 '16 at 07:54
  • Could you try `value=` instead of `ng-value=` ? – Martijn Welker Feb 16 '16 at 07:58