1

HTML:

<div ng-app="myApp" ng-controller="myCtrl">       
  <label ng-repeat="x in list">
    <input type="radio" ng-model="test" value="x" >{{x}} 
  </label>   
  <br>
  Exec type: {{test}}   
</div>

JS:

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) { 
$scope.list = ["xxx", "yyyy"];
  $scope.test = "";
});

JS Fiddle: http://jsfiddle.net/0ku4jvsn/5/

Nothing is bound with $scope.test. This line: Exec type: {{test}} is showing nothing.

1 Answer 1

3

You should use $parent.test when you bind your ng-model because you are in a ng-repeat

<label ng-repeat="x in list">
    <input type="radio" ng-model="$parent.test" value="{{ x }}" >{{x}} 
</label>

To selected a default value, just assign your model with your desired value

var app = angular.module('myApp', []);

app.controller('myCtrl', function($scope) { 
    $scope.list = ["xxx", "yyyy"];
    $scope.test = $scope.list[0];
});

https://jsfiddle.net/0ku4jvsn/6/

Sign up to request clarification or add additional context in comments.

1 Comment

how can I make "xxx" by default selected ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.