2
  <div class="radio-inline" ng-repeat="customerOption in customerOptions">
       <input type="radio" name="customer" ng-change="getCustomers(customerType)" ng-model="customerType" ng-value="customerOption.Key" ng-checked="customerOption.Checked" />{{customerOption.Value}}
  </div>

This doesn't seem to do anything:

 ng-attr-id="{{customerOption.Value}}" 

or:

 ng-attr-id="customerOption.Value" 

or:

 id="customerOption.Value" 

These puts exactly that line in the html

6
  • Why are you trying to set the id attribute anyway? Commented Dec 15, 2014 at 13:53
  • @BenjaminGruenbaum I am trying to pre-select one of the radio buttons. Commented Dec 15, 2014 at 13:53
  • I guess that you might have a good reason... try ng-attr-id="{{customerOption.Value}}" although there are few good reasons to do this. Commented Dec 15, 2014 at 13:54
  • @BenjaminGruenbaum I am trying to pre-select one of the radio buttons. -- you don't need an ID to do it, use ng-model that's hooked to the radio button Commented Dec 15, 2014 at 13:57
  • @maurycy how would I do that with the model? Commented Dec 15, 2014 at 13:58

1 Answer 1

2

That's a quick plunker to show use of ng-model for default radio

http://plnkr.co/edit/F3M2fzLaYYrIwQdtuwHT?p=preview

app.controller('MainCtrl', function($scope) {
  $scope.gender = 'female';
});

<body ng-controller="MainCtrl">
  <input type="radio" name="sex" value="male" ng-model="gender">Male
  <br>
  <input type="radio" name="sex" value="female" ng-model="gender">Female
</body>
Sign up to request clarification or add additional context in comments.

2 Comments

I am looping through the customerOptions array. How would I access the specific one that I want to set?
You only needs to set the model to correct value, i've in my example 2 values [male, female] so I've set $scope.gener which is a model for both radios to correct string value

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.