4

I have an ng-repeat with a bunch of radio buttons inside:

<div class="panel panel-default" ng-repeat="offer in vm.offerList">
    ...    
    <td ng-show="offer.edit">
        <div class="row">                        
            <input type="radio" name="before" ng-model="offer.before" value="false">
            <input type="radio" name="before" ng-model="offer.before" value="true">
       </div>
   </td>
   ...
</div>

The model offer.before has the correct value, however, when the row is shown, the radio button doesn't appear checked. Why is this happening? I need the radio button to show the selected value.

This is a fiddle example of my problem: http://jsfiddle.net/danielrvt/dpoLdgjq/

1 Answer 1

10

Because anything inside attribute value gets toString() like value true will be considered as 'true' & it will looks for 'true'(string) instead of true(boolean).

Better use ng-value instead of value attribute. It will treat true value as in true of type boolean only.

Additionally in your case you have to add name attribute to be unique for each radio button group each offer element radio will be considered as unique form element.

Markup

<div class="row">
    {{offer.before}}
    <input type="radio" name="before{{$index}}" ng-model="offer.before" ng-value="false">
    <input type="radio" name="before{{$index}}" ng-model="offer.before" ng-value="true">
</div>

Forked Fiddle

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

11 Comments

@ChiefTwoPencils I updated answer with OP's fiddle.. Though thanks for heads up :)
Why for example is this working perfectly but it doesn’t when the type=‘radio’ ??? <input type='checkbox' ng-init='checkStatus=false' ng-model='checkStatus' ng-click='doIfChecked(checkStatus)'>
Can you please share a fiddle/plunkr?
What is the issue, I tried it, but can not figure what issue you're facing. Can you please elaborate more on it? w3schools.com/code/tryit.asp?filename=GLX41P26BSR2
|

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.