I'm unable to retrieve the value of the Radio Group using AngularJS 1.4.7 with Ionic 1.1.1;
Any ideas would be great, thanks.
See codepen snippet of the issue: http://codepen.io/angsar/pen/RWdvrO
HTML
<html ng-app="app">
<head>
<link rel="stylesheet" href="http://code.ionicframework.com/1.1.1/css/ionic.min.css" />
<link href="http://code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css" rel="stylesheet">
<script src="http://code.ionicframework.com/1.1.1/js/ionic.bundle.js"></script>
</head>
<body ng-controller="myCtrl">
<ion-content padding="true">
<form class="list" ng-submit="Pass(test)">
<p>Selected Sample: {{test.val}}</p>
<ion-radio ng-model="test.val" ng-value="s1">Sample 1</ion-radio>
<ion-radio ng-model="test.val" ng-value="s2">Sample 2</ion-radio>
<button class="button button-energized button-large icon-right button-full">Test</button>
</form>
</ion-content>
</body>
</html>
Javascript
angular.module('app', ['ionic'])
.controller('myCtrl', function($scope) {
$scope.Pass = function($test) {
alert("Test: "+$test.val);
}
});
Try the following:
angular.module('app', ['ionic'])
.controller('myCtrl', function($scope) {
$scope.test = {};
$scope.Pass = function($test) {
alert("Test: "+ $scole.test.val);
}
});
Explanation:
$test
is not defined in your $scope
. $
have a special meaning in angular, so you shouldn't use them as regular variable namesUpdate: It's also important to singelquote a string value within the double quoted ng-value
<ion-radio ng-model="test.val" ng-value="'s1'">Sample 1</ion-radio>